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

TypeError caused by MongoError: Invalid Operation, no operations specified

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.1.3
    • Component/s: None
    • Environment:
      Docker for Mac
      Dockerfile - FROM node:8.9.4
    • None
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Given a callback for UnorderedBulkOp e.g. execute((err, result) => { ... }) which returns undefined

      When an invalid operation error is raised via the callback

       

      (node:1) DeprecationWarning: Cursor.each is deprecated. Use Cursor.forEach instead.
      ...
      { MongoError: Invalid Operation, no operations specified
          at Function.create (/opt/app/node_modules/mongodb-core/lib/error.js:43:12)
          at toError (/opt/app/node_modules/mongodb/lib/utils.js:149:22)
          at UnorderedBulkOperation.bulkExecute (/opt/app/node_modules/mongodb/lib/bulk/common.js:939:31)
          at UnorderedBulkOperation.execute (/opt/app/node_modules/mongodb/lib/bulk/unordered.js:125:22)
          at cursor.each (/opt/app/lib/db/client.js:99:18)
          at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:128:55)
          at cursor.close (/opt/app/node_modules/mongodb/lib/operations/cursor_ops.js:95:62)
          at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:128:55)
          at completeClose (/opt/app/node_modules/mongodb/lib/cursor.js:887:14)
          at AggregationCursor.Cursor.close (/opt/app/node_modules/mongodb/lib/cursor.js:906:10)
          at cursor.next (/opt/app/node_modules/mongodb/lib/operations/cursor_ops.js:95:23)
          at result (/opt/app/node_modules/mongodb/lib/utils.js:414:17)
          at executeCallback (/opt/app/node_modules/mongodb/lib/utils.js:406:9)
          at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:128:55)
          at cursor._next (/opt/app/node_modules/mongodb/lib/operations/cursor_ops.js:182:5)
          at handleCallback (/opt/app/node_modules/mongodb-core/lib/cursor.js:203:5)
        driver: true,
        name: 'MongoError',
        [Symbol(mongoErrorContextSymbol)]: {} }
      /opt/app/node_modules/mongodb/lib/utils.js:132
            throw err;

       

      Then the following exception occurs 

      TypeError: Cannot read property 'options' of undefined
          at UnorderedBulkOperation.execute (/opt/app/node_modules/mongodb/lib/bulk/unordered.js:126:19)
          at cursor.each (/opt/app/lib/db/client.js:99:18)
          at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:128:55)
          at cursor.close (/opt/app/node_modules/mongodb/lib/operations/cursor_ops.js:95:62)
          at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:128:55)
          at completeClose (/opt/app/node_modules/mongodb/lib/cursor.js:887:14)
          at AggregationCursor.Cursor.close (/opt/app/node_modules/mongodb/lib/cursor.js:906:10)
          at cursor.next (/opt/app/node_modules/mongodb/lib/operations/cursor_ops.js:95:23)
          at result (/opt/app/node_modules/mongodb/lib/utils.js:414:17)
          at executeCallback (/opt/app/node_modules/mongodb/lib/utils.js:406:9)
          at handleCallback (/opt/app/node_modules/mongodb/lib/utils.js:128:55)
          at cursor._next (/opt/app/node_modules/mongodb/lib/operations/cursor_ops.js:182:5)
          at handleCallback (/opt/app/node_modules/mongodb-core/lib/cursor.js:203:5)
          at _setCursorNotifiedImpl (/opt/app/node_modules/mongodb-core/lib/cursor.js:561:38)
          at self._endSession (/opt/app/node_modules/mongodb-core/lib/cursor.js:569:46)
          at AggregationCursor.Cursor._endSession (/opt/app/node_modules/mongodb-core/lib/cursor.js:194:5)

       

       

      The following lines of code appear to show only two additional return types of a promise or a callback return value.

      https://github.com/mongodb/node-mongodb-native/blob/79da11f220b567c2db2c956c51e76fa40b18acd6/lib/bulk/common.js#L941

      Immediately below another return type is an object of options and callback props.

      https://github.com/mongodb/node-mongodb-native/blob/79da11f220b567c2db2c956c51e76fa40b18acd6/lib/bulk/common.js#L944

      Usage of the return value assumes an object is returned from the callback and doesn't account for any promise/async behavior as given on line 941 above. I suspect the following is the source of the TypeError.

      https://github.com/mongodb/node-mongodb-native/blob/79da11f220b567c2db2c956c51e76fa40b18acd6/lib/bulk/unordered.js#L124-L131

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            mrmusa Musa Siddeeq
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              None
              None
              None
              None