anchor.diff:    catch
       _:_ -> false
     end,
  -  true.+  true.
  +
  +is_equal_bsons(LHV, RHV) ->
  +    LHVSorted = sort_bson_data(LHV),
  +    LHVSorted =:= sort_bson_data(RHV).
  +
  +is_equal_lists_of_bsons(LHV, RHV) ->
  +    LHVSorted = lists:sort([sort_bson_data(BSON) || BSON <- LHV]),
  +    LHVSorted =:= lists:sort([sort_bson_data(BSON) || BSON <- RHV]).
  +
  +sort_bson_data(BSON) ->
  +    lists:keydelete('_id', 1, lists:sort(bson:fields(BSON))).
  
positive.code:   ]),
  
    %test match and sort
    {true, {result, Res}} = mongo:command(Connection, {aggregate, <<"test">>, pipeline, [{'$match', {key, <<"test">>}}, {'$sort', {tag, 1}}]}),
    ?debugFmt("Got ~p", [Res]),
    [
      {'_id', _, key, <<"test">>, value, <<"one">>, tag, 1},
      {'_id', _, key, <<"test">>, value, <<"two">>, tag, 2},
      {'_id', _, key, <<"test">>, value, <<"three">>, tag, 3},
      {'_id', _, key, <<"test">>, value, <<"four">>, tag, 4}
    ] = Res,
  
    %test match & sort with limit
    {true, {result, Res1}} = mongo:command(Connection,
      {aggregate, <<"test">>, pipeline,
        [
          {'$match', {key, <<"test">>}},
          {'$sort', {tag, 1}},
          {'$limit', 1}
        ]}),
    ?debugFmt("Got ~p", [Res1]),
    [
      {'_id', _, key, <<"test">>, value, <<"one">>, tag, 1}
    ] = Res1,
    Config.
  
  update(Config) ->
  
negative.code:     'ratings.0.rating', 2
    }},
    mongo:update(Connection, Collection, {'_id', 100}, Command3),
    [Res4] = find(Connection, Collection, {'_id', 100}),
    ct:log("Got ~p", [Res4]),
    true = is_equal_bsons(
             Res4,
             {'_id', 100,
              sku, <<"abc123">>,
              quantity, 500,
              instock, true,
              reorder, false,
              details, {model, "14Q3", make, "zzz"},
              tags, ["coats", "rain gear", "clothing"],
              ratings, [{by, "ijk", rating, 2}],
              expired, true}),
    Config.
  
  
  