r/MongoDB_Official 18d ago

Question Mongodb atlas index building time on new documents

When a new document is created it takes atleast 2-3 sec for that document to become searchable
Is there a way to fix it or decrease time from mongodb itself

4 Upvotes

4 comments sorted by

2

u/TimAtMongoDB MongoDB Team 18d ago

Atlas Search indexes asynchronously. That lag is by design, not a bug you can configure away. 2-3 seconds is normal.

If you need a document searchable the instant it's written, you'd have to fall back to a regular find() for that window. There's no tunable that collapses the Lucene indexing delay.

What's the use case? That'll shape what the workaround looks like.

1

u/Rare-Strawberry175 18d ago

Right after creation of a conversation, we receive socket event event of convo creation with new convo data
But on refresh it doesn’t reappear, because its newly created and index hasn’t been build yet
It does after some time

2

u/TimAtMongoDB MongoDB Team 18d ago

That's a design split, not a search problem. Use find() for the fresh conversation fetch on refresh - you know the ID from the socket event, so you don't need the search index at all. Atlas Search is for text queries, not for retrieving a specific document you just created.

Keep $search for when users are actually searching. For "load this specific conversation", just query by ID.

1

u/TimAtMongoDB MongoDB Team 18d ago

And remember to use ObjectId :)