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

initialising change stream results in: TypeError: Cannot read property 'documents' of null

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.5.10
    • Affects Version/s: 3.5.7
    • Component/s: None

      This happened when initialising a change stream using a resume token (via `startAfter` option).

      full stack trace:

      TypeError: Cannot read property 'documents' of null
       at /app/node_modules/mongodb/lib/change_stream.js:307:31
       at handleCallback (/app/node_modules/mongodb/lib/core/cursor.js:32:5)
       at /app/node_modules/mongodb/lib/core/cursor.js:685:38
       at /app/node_modules/mongodb/lib/core/cursor.js:694:39
       at ChangeStreamCursor._endSession (/app/node_modules/mongodb/lib/core/cursor.js:395:7)
       at _setCursorNotifiedImpl (/app/node_modules/mongodb/lib/core/cursor.js:694:10)
       at setCursorNotified (/app/node_modules/mongodb/lib/core/cursor.js:685:3)
       at done (/app/node_modules/mongodb/lib/core/cursor.js:451:16)
       at queryCallback (/app/node_modules/mongodb/lib/core/cursor.js:500:18)
       at /app/node_modules/mongodb/lib/core/cursor.js:550:9
       at executeCallback (/app/node_modules/mongodb/lib/operations/execute_operation.js:70:5)
       at callbackWithRetry (/app/node_modules/mongodb/lib/operations/execute_operation.js:118:14)
       at /app/node_modules/mongodb/lib/operations/command_v2.js:90:9
       at /app/node_modules/mongodb/lib/cmap/connection_pool.js:352:13
       at handleOperationResult (/app/node_modules/mongodb/lib/core/sdam/server.js:489:5)
       at MessageStream.messageHandler (/app/node_modules/mongodb/lib/cmap/connection.js:270:5)
       at MessageStream.emit (events.js:209:13)
       at processIncomingData (/app/node_modules/mongodb/lib/cmap/message_stream.js:144:12)
       at MessageStream._write (/app/node_modules/mongodb/lib/cmap/message_stream.js:42:5)
       at doWrite (_stream_writable.js:428:12)
       at writeOrBuffer (_stream_writable.js:412:5)
       at MessageStream.Writable.write (_stream_writable.js:302:11)
       at TLSSocket.ondata (_stream_readable.js:722:22)
       at TLSSocket.emit (events.js:209:13)
       at addChunk (_stream_readable.js:305:12)
       at readableAddChunk (_stream_readable.js:286:11)
       at TLSSocket.Readable.push (_stream_readable.js:220:10)
       at TLSWrap.onStreamRead (internal/stream_base_commons.js:182:23)
      

      I tried to debug it by placing console.log in various places and comparing it to a case in which the change stream initialised without issues. In the case which lead to the above error the cursor returned by initial aggregation (logged here) operation didn't have postBatchResumeToken property and had id = Long(0):
       

      {
        firstBatch: [],
        id: Long { _bsontype: 'Long', low_: 0, high_: 0 },
        ns: 'my-db.my-collection'
      }
      

      using:
      mongodb@35.7
      node@12.14.0

            Assignee:
            eric.adum@mongodb.com Eric Adum (Inactive)
            Reporter:
            adrian.gierakowski@deversifi.com Adrian Gierakowski
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: