Document not found sometimes using same query

We are running mongo in the replica set with read and write taking place from the master node. Now it is happening intermittently that the same document can be found with a query and sometimes it didn’t returns the document using exact same query.

Env variable:
Language: Java client for fetching mongo documents.
Cluster: Replica set mode

Client Verison: spring data mongo 3.0.7
Mongo version: 4.2.9

We found that issue is happening when query is run on indexes. It sometimes intermittently not returning the exact document.

Hi @vipul_tiwari, welcome to our forums.

I’m not certain if this question is directly related to an exercise or lesson in the M312 course, as such it may be better asked in the “Drivers & ODM” topic.

In terms of the scenario, you describe there could be many reasons why the same query criteria are returning or not returning a specific document. It is most likely related to the point you mention that reading and writing is taking place and that the specific document and a field used in the criteria is being updated. The field updates are potentially causing it to match the query criteria until it is updated at which point, one or more fields are changed resulting in the document no longer matching the query criteria exactly. This would be expected behavior.

Beyond this explanation, I think you should move this post to the other forum to more deeply dive into the reasons why this may be occurring.

If you have a question related to any of the lessons or exercises on M312, we’d be happy to answer them in this forum.

Kindest regards,

Thanks @Eoin_Brazil. We aren’t updating the documents for search criteria, anyways I have moved the post to Drivers and ODM. Let see if they can provide help.

hello, did you found the solution? I have an exactly same problem here. I don’t setup replica set. Thanks