On 8 June 2016 at 22:36, John Meinel <j...@arbash-meinel.com> wrote:

> ...
>>
>
>
>>
>>   ops := []txn.Op{{
>>       C: "collection",
>>       Id: ...,
>>       Assert: bson.M{
>>           "some-field.A": "foo",
>>           "some-field.B": 99,
>>       },
>>       Update: ...
>>   }
>>
>> ...
>>
>>
> If loading into a bson.M is the problem, wouldn't using a bson.M to start
> with also be a problem?
>

No this is fine. The assert above defines that each field should match the
values given. Each field is checked separately - order doesn't matter.

This would be a problem though:

  ops := []txn.Op{{
      C: "collection",
      Id: ...,
      Assert: bson.M{"some-field": bson.M{
          "A": "foo",
          "B": 99,
      },
      Update: ...
  }

>
In this case, mgo is being asked to assert that some-field is an embedded
document equal to a document defined by the bson.M{"A": "foo", "B": 99}
map. This is what's happening now when you provide a struct value to
compare against a field because the struct gets round-tripped through
bson.M. That bson.M eventually gets converts to actual bson and sent to
mongodb but you have no control of the field ordering that will ultimately
be used.

- Menno
-- 
Juju-dev mailing list
Juju-dev@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/juju-dev

Reply via email to