[SERVER-42274] Using forEach to iterate a cursor results in error "hasNext: false" in v1.3.0 Created: 18/Jul/19 Updated: 06/Dec/22 Resolved: 22/Jul/19 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor - P4 |
| Reporter: | João Agnelo | Assignee: | Backlog - Triage Team |
| Resolution: | Incomplete | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Attachments: |
|
| Assigned Teams: |
Server Triage
|
| Operating System: | ALL |
| Steps To Reproduce: | db = db.getMongo().getDB("usa"); cursor = db.cities.find({_id: '17662'}).limit(100); cursor_explain = cursor.explain(); db.getSisterDB("results")[TEST_NAME + ".explain"].insert({explain: tojson(cursor_explain)}); cursor.forEach(function(doc) {db.getSisterDB("results")[TEST_NAME].insert(doc);}); |
| Participants: |
| Description |
|
While performing an academic experiment based on the random generation of a large set of tests to exercise the Query Language of MongoDB (all of which syntactically valid), a possible bug was detected in several tests while iterating a Cursor object to store query results to a new collection. It is unknown to us why it occurred, but because the method forEach() is the one responsible for iterating a Cursor object through the while( hasNext() ) { next() } loop, it is unlikely that the actual code in the respective test cases could have caused such an error. Additionally, because no similar bug has been reported, we decided to do so for consistency-sake, even though it was found on very very old and out-of-date version of MongoDB and may now hold little importance. Attached is a zip file with all the 14 test cases in which this event occurred. For clarity, note that each test case (i.e., file) contains a set of 4 "sub-"test cases, which respectively test the find(), find().hint(), find.sort() and find.hint().sort() method combinations. We suspect that the error is thrown by the forEach() method, which is used once per each of the 4 blocks of code. The tests were carried out on the USA cities database. |
| Comments |
| Comment by Danny Hatcher (Inactive) [ 22/Jul/19 ] |
|
Due to the extreme old age of this version of MongoDB, I'm going to close this ticket. Please re-open if you are able to reproduce against a modern version. |