$inc consistency with "local" read concern

We have Mongo node with two replicas. Assuming write concern is set to “majority” and read concern is “local” - is it possible to update the document using $inc and read the old value afterwards?
For example:

Say we have the current document (all writes have been successfully replicated to all members):

     _id: 1,
     sku: "abc123",
     quantity: 1 

And we execute the following update:

   { sku: "abc123" },
   { $inc: { quantity: -1 } }

And than reading the doc:
find( { sku: "abc123" } )

Is it possible that primary node and replica 1 were updated but we are getting the “old” data from replica 2 (quantity=1 instead of quantity=0)?
As $inc should get the current value before set a new one, is it considered write operation, or write AND read operation?

Hi @Itay_Maoz ,

If you use a primary read preference why would you read from a stale secondary? You can also use findAndUpdate to get the value after incrementing.

However, when you read from secondaries there is a chance you may read stale data , so in those scenarios consider reading specifically from a primary.


Thanks @Pavel_Duchovny , my question is basically for learning, I dont have a concrete issue that I am trying to solve. I think I might misunderstood what “local” read concern is if you say that I use primary read preference. doest “local” means that the document will return from the first node that answers? be it primary or secondary…?
Thanks again

@Itay_Maoz ,

Read concern “local” refers to the data durability guarantee. If you use “local” this means that the instance you are connected to considering your read prefernce (default Primary) will return data even if it was written only on the local node.

So even if you use local the data on primary should read the incremented value . However, if a failover will occurs the written data might be rolled-back and since you are reading with “local” you might get a value which is not majority commited.