Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-6367

Change in cursor behavior, not all documents are returned

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 6.9.0, 6.8.2
    • Affects Version/s: 6.8.0
    • Component/s: None
    • 0
    • Not Needed
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      Use Case

      Recently upgraded to the MongoDB driver version 6.8.0. We were running on 6.7.0 before.

      Documents are versioned and have an _id of the structure.

      _id: { id: ObjectId; version: number }

      We were consuming a cursor using the following pattern in a JavaScript generator.
      We always return the first matching document and then iterate until a certain condition is met.

       

      const documentId = ...some ObjectId;
      const cursor = collection.find({ '_id.id': documentId }, { sort: { '_id.version': -1 } });
      const document = await cursor.next();
      yield document;
      for await (const document of cursor) {
        ...
        yield document;
        // break out of loop depending on a condition
      } 

      Suppose I have 2 documents matching the filter. The cursor.next() call returns one of them, but since version 6.8.0 it never goes inside of the loop again. Downgrading to 6.7.0 worked fine.

      Is this because cursor responses are now parsed lazily?

      https://github.com/mongodb/node-mongodb-native/releases/tag/v6.8.0

       

      User Experience

      • I would expect looping through my cursor to return all the documents matchign the filter.
      •  

            Assignee:
            warren.james@mongodb.com Warren James
            Reporter:
            geersch@gmail.com Christophe Geers
            Neal Beeken
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: