Cant find doc right after creation

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.

  1. you are not looking on the correct server, database or collection
  2. you are not using the appropriate API
  3. you are not performing the correct query
  4. 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?

2 Likes

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.

  1. Are you able to retrieve data through mongo shell.
  2. Are you using any drivers to insert/update/delete? If yes, what are the version for the same?
  3. 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.
  4. The type of your mongod deployment
  5. How much time does it take for a query to respond with mongod under load.

Thanks
Aasawari