Raingo Lee
Raingo Lee

Reputation: 45

query and insert simultaneously to a mongodb collection

What will happen to query and insert simultaneously to a mongodb collection.

For example,

process-I:

for page in coll.find():
     # access page

process-II:

for page in gen_pages():
     # coll.insert(page)

Will the find() in process-I return the new insertions from process-II?

Suppose that coll is huge and process-II will terminate before process-I

Sincere Thanks~

Upvotes: 1

Views: 564

Answers (1)

WiredPrairie
WiredPrairie

Reputation: 59793

Cursors are not isolated in MongoDB. So, assuming that the find method uses a MongoDB cursor internally (which I believe it does), the results are affected by changes to the data from inserts, etc. So, depending on the nature of the query and the data that was inserted, the new values could appear in the results. There are a number of factors including where the cursor is currently pointing, sorting, when locks are taken, number of documents requested by the cursor operation, ....

Upvotes: 1

Related Questions