6

Sometimes we observe the next case:

  • We insert a document to MongoDB with write concern w: 1 via mongos router that writes to primary replica of shard A.
  • We read this document from MongoDB with default local read concern via mongos router that should read from primary replica of shard A.
  • This findOne returns null as if the document is not found.
  • (Actually it is Python driver pymongo - find_one() and it returns None).
  • We sleep 0.1 seconds and retry the read.
  • On step 2-5 the document is finally read successfully.

We found:

  • Such cases are observed more often when a lot of documents are inserted to this collection quickly.
  • We suspected such inserts lead to chunking and migration of chunk from shard A to shard B.
  • While a document is migrating, could it be unavailable for reads for a short time?
  • But there is only one insert to only one shard in db.oplog.rs, no fromMigrate flags.

Why does it happen? How to deal with it correctly?

These false-positive "not found"-s may lead to faulty atomic-find-or-create via $setOnInsert?

Denis Ryzhkov
  • 2,321
  • 19
  • 12
  • Some having the same issue [here](https://www.mongodb.com/community/forums/t/mongorepository-save-issue/12124/4) but no solution has been suggested at the time of writting this comment ! – Youssef NAIT Aug 19 '22 at 10:24

0 Answers0