What is server session in mongodb?

I just learned about the cursor concept in this doc.
But what does “cursor opened within/not within a server session” mean?

1 Like

Hello @111661 ,

Welcome to The MongoDB Community Forums! :wave:

Cursor points to the set of documents known as result set that are matched to the query filter. A server session is created when a client connects to the server and begins an operation such as a query, insert, update, or delete. It includes information about the client’s transaction and can be used to execute multiple operations in a single transaction.

When a cursor is opened within a server session, it is associated with that session and can be used to retrieve query results for as long as the session is active. This allows clients to iterate through the cursor results over multiple network round trips and across multiple database operations.

On other hand, a cursor that is not opened within a server session is only active for the duration of the query operation that created it. Once the query completes and the cursor is exhausted or closed, the cursor’s results are no longer available for retrieval.

Please go through Server Sessions and Cursor Behaviors documentation to get more detailed information.


1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.