Saturday, 15 April 2017

Mongo bulkWrite from JSON file

For my test suite, I want to bulkWrite test info in the database, and then bulk delete any of the test info entered throughout the test to come back to a clean slate. I do so by running a bulkWrite on the db to which I pass the content of a JSON file loaded via nodeJS's require statement.

The problem is that for the dataset

[ { deleteOne: { username: 'test-author' } } ]

passed to models[key].collection.bulkWrite(action[key]), where key is the name of the model of interest and action is the JSON file,I get the following error:

{ MongoError: Wrong type for 'q'. Expected a object, got a null.
    at Function.MongoError.create (/var/www/website/server/node_modules/mongodb-core/lib/error.js:31:11)
    at /var/www/website/server/node_modules/mongodb-core/lib/connection/pool.js:483:72
    at authenticateStragglers (/var/www/website/server/node_modules/mongodb-core/lib/connection/pool.js:429:16)
    at Connection.messageHandler (/var/www/website/server/node_modules/mongodb-core/lib/connection/pool.js:463:5)
    at Socket.<anonymous> (/var/www/website/server/node_modules/mongodb-core/lib/connection/connection.js:339:20)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:548:20)
  name: 'MongoError',
  message: 'Wrong type for \'q\'. Expected a object, got a null.',
  ok: 0,
  errmsg: 'Wrong type for \'q\'. Expected a object, got a null.',
  code: 14,
  codeName: 'TypeMismatch' }

I have done some research and have been unable to find a solution to this problem. The error itself is pretty meaningless, so I can't grasp much out of it. Any idea how to solve the problem?

Any help would be greatly appreciated! Cheers!



via Philippe Hebert

No comments:

Post a Comment