Cursor isolation in mongoDB

93 views
Skip to first unread message

Saumyarajsinh zala

unread,
Jan 30, 2014, 2:44:24 AM1/30/14
to mongod...@googlegroups.com
First of all please forgive me for asking a silly question but I am new to mongodb and learning about cursors. I have a question that why we need cursor isolation?.The manual says "intervening write operations on a document may result in a cursor that returns a document more than once if that document has changed. ". I am not able to understand this. I would be glad if someone can throw more light on it or give some example. Thankyou.

Asya Kamsky

unread,
Jan 30, 2014, 8:21:47 PM1/30/14
to mongodb-user
First, I want to mention that if you are talking about the $isolated special parameter (formerly named $atomic) it's not a good idea to use it for a number of reasons (and I hope it will be deprecated at some point).

The reason that a document can be encountered more than sometimes when a document is updated and it grows in size, it needs to be moved.

Imagine you are reading documents "a,b,c,d,e" (as a collection scan) and you've read through d when the batch you got is used up and the driver goes to the server for the next batch.  Meanwhile someone updated "b" which causes it to outgrow its allocated space and be moved ... to the end of the collection.  So your next batch is "e,b" - meaning the entire set you read was a,b,c,d,e,b - but the first time you read "b" it was before the change to it was made, and the second time you read it it was after the change.

When you iterate over documents they are not representing a single instant in time.  This is one of subtle results of that fact.

Asya



On Wed, Jan 29, 2014 at 11:44 PM, Saumyarajsinh zala <saumy...@gmail.com> wrote:
First of all please forgive me for asking a silly question but I am new to mongodb and learning about cursors. I have a question that why we need cursor isolation?.The manual says "intervening write operations on a document may result in a cursor that returns a document more than once if that document has changed. ". I am not able to understand this. I would be glad if someone can throw more light on it or give some example. Thankyou.

--
--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb
 
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages