[SERVER-13354] delete operator in db.collection.find().forEach() sometimes behaves incorrectly Created: 26/Mar/14 Updated: 16/Oct/21 Resolved: 07/Apr/14 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | JavaScript |
| Affects Version/s: | 2.4.4, 2.4.8, 2.6.0-rc2 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Vladimir Shakhov | Assignee: | Kamran K. |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Operating System: | ALL | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Steps To Reproduce: | here is a somewhat minimal test case;
results:
and fail
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Participants: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
Hi, I'm using db.collection.find().forEach() and depending on collection size, when it grows larger than i was able to reproduce it in both |
| Comments |
| Comment by Kamran K. [ 07/Apr/14 ] | |||||||||||
|
Thanks for the update! I'm resolving this as 'works as designed'. | |||||||||||
| Comment by Vladimir Shakhov [ 04/Apr/14 ] | |||||||||||
|
Oh, thanks! adding 'snapshot()' to update script worked | |||||||||||
| Comment by Kamran K. [ 30/Mar/14 ] | |||||||||||
|
Hi Vladimir, It looks like the cursor is returning some documents multiple times because the updates are causing document moves. http://docs.mongodb.org/manual/faq/developers/#how-do-i-isolate-cursors-from-intervening-write-operations has more information about cursor isolation and ways to avoid this issue. For this particular case, you can check for the presence of the 'map' field to avoid updating a document more than once:
Without the additional obj.map === undefined check, obj.map.a and obj.map.b will both be set to undefined because the obj.a and obj.b fields have been previously deleted from the document in an earlier iteration. Hope that helps. |