We have a single client that serially writes on two documents (with {w:1}
).
For example, the original documents may be:
{_id: "a", value: 0}
,
{_id: "b", value: 0}
and the client updates document "a" to {_id: "a", value: 1}
and then, after the update completes, the client updates document "b" to {_id: "b", value: 1}
.
A second client calls find({})
afterwards. The second client reads from a secondary, which may have not received all the changes.
Obviously it can read the following states:
{_id:"a",value:0}
,{_id:"b",value:0}
{_id:"a",value:1}
,{_id:"b",value:0}
{_id:"a",value:1}
,{_id:"b",value:1}
which are "real" states on the primary (at some moment in the past).
Can the second client see a state like: {_id:"a",value:0}
,{_id:"b",value:1}
? Notice that this state never existed on the primary.
P.S. The explanation here says:
Secondaries ... apply write operations in the order that they appear in the oplog.
Does that mean the secondaries change their documents at the same order they were updated on the primary?
P.S. does find
cursors "freeze" the state of the documents that they are reading (i.e. ignore changes that were made after the cursor was created)? Could things be different if I used find(...).sort({_id:-1})
or if document "a"'s id was "c" (i.e. larger than "b")?
Thanks