[SERVER-1199] Iterating through a query result and adding new data to the queried objects results in iterating over some objects twice Created: 07/Jun/10  Updated: 07/Mar/14  Resolved: 07/Jun/10

Status: Closed
Project: Core Server
Component/s: Querying, Write Ops
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Alan Assignee: Eliot Horowitz (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

GNU/Linux Ubuntu (Lucid) mongodb-unstable package (version 20100604)


Attachments: File mongo_find_and_update.py    
Participants:

 Description   

Iterating through a resultset and adding news fields to the objects results in a corrupted iterator.

A simple test like the following code iterates many times over the same objects ... am I missing something? (see the attached file for a complete example)

    1. sample code ##
      total_obj = db.test.find().count()
      count = 0
      for item in db.test.find():
      db.test.update( {'_id':_id}

      , {'$set' : {'some_new_data' : random.randint(0, 1000)}})
      count = count +1

print count,total_obj

    1. /sample code ##

script usage:
python mongo_find_and_update.py test_db



 Comments   
Comment by Eliot Horowitz (Inactive) [ 07/Jun/10 ]

Your adding a field using $set, so that will make the object larger forcing a move.

Comment by Alan [ 07/Jun/10 ]

thanks for your answer ... but from what I understand from the documentation, modifying objects should be fine as long as the '_id' is not modified and the size of the returned documents is not affected by the update (this is the case in my example) ... am I wrong?

Comment by Eliot Horowitz (Inactive) [ 07/Jun/10 ]

this is known/expected behavior
see http://www.mongodb.org/display/DOCS/How+to+do+Snapshotted+Queries+in+the+Mongo+Database

Generated at Thu Feb 08 02:56:21 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.