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

4.0 Cursor with .limit(1) returns null instead of doc

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Blocker - P1
    • Resolution: Gone away
    • Affects Version/s: 4.0.0
    • Fix Version/s: None
    • Component/s: Shell
    • Labels:
      None
    • Documentation Changes:
      Not Needed

      Description

      It seems setting a limit(1) on a cursor will cause it to return null on `next()` even if there is a document to return IF you call 'hasNext()' before calling next(). It will return true for `hasNext()`.

      Steps to recreate:

      $ node --experimental-repl-await
      >  const m = require('mongodb'); const c = await m.MongoClient.connect('mongodb://127.0.0.1:27017', { useUnifiedTopology: true }) // or wherever you have a db
      > await c.db('test').collection('coll').insertMany([{x: 1}, {x: 2}, {x: 3}])
      > const cursor = c.db('test').collection('coll').find()
      > const cursor2 = c.db('test').collection('coll').find().limit(1)
      > await cursor.hasNext() --> true
      > await cursor2.hasNext() --> true
      > await cursor.next() --> { x: 1 }
      > await cursor2.next() ------> THIS RETURNS NULL, IT SHOULD RETURN THE DOC
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              eric.adum Eric Adum (Inactive)
              Reporter:
              anna.herlihy Anna Herlihy (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: