Hi. I recently faced a problem below:
When I create doc, mongo returns me info about inserted doc. I take the id and try to find this doc by id that i received. and when base is on some load it returns null.
I want to understand why this happens. And what to do if i want to update the document in short time after creation.
You received acknowledgement that the document was created but you cannot find the document.
Many reasons may cause that.
- you are not looking on the correct server, database or collection
- you are not using the appropriate API
- you are not performing the correct query
- if you do not write and read with majority
#1 for us is very hard to check
We could check #2 or #3 only if you share your code.
What do you mean by
What is base? What do you mean by some load?
Hi, thank you for reply
By base I mean database server. By some load I mean when database server receives a lot of requests and kind of busy.
There is no mistakes in my code. When database server is not on load - i can find the document.
Since you are confirming that it is not #1, #2 or #3, then it must be #4
If you do not write with majority commit, then you have to enforce reading from primary.
Hi @Igor_Tikush and welcome to the community!!
I agree to what @steevej mentions and also would need a few more details to have more clarity on the issue mentioned.
- Are you able to retrieve data through mongo shell.
- Are you using any drivers to insert/update/delete? If yes, what are the version for the same?
- Are you trying to make concurrent request to
mongod
. To understand more on how concurrent requests are handled in MongoDB, please follow the documentation on FAQs related to concurrency to understand the concepts of lock based mechanisms. - The type of your
mongod
deployment - How much time does it take for a query to respond with
mongod
under load.
Thanks
Aasawari