In particular I'm trying to use an ObjectId in a find:
// in a migration script
const ObjectId = require('mongodb').ObjectId;
// ...
up: function (db, cb) {
db.collection('persons').findOne({_id: ObjectId('580e1102ac5378af70f4d9f4'}, (err,response)=>{
//error!
})
}
Error!
TypeError: Argument must be a string
at TypeError (native)
at Buffer.write (buffer.js:763:21)
at serializeObjectId (./node_modules/mongration/node_modules/bson/lib/bson/parser/serializer.js:242:10)
at serializeInto (./node_modules/mongration/node_modules/bson/lib/bson/parser/serializer.js:699:17)
at serializeObject (./node_modules/mongration/node_modules/bson/lib/bson/parser/serializer.js:280:18)
at serializeInto (./node_modules/mongration/node_modules/bson/lib/bson/parser/serializer.js:705:17)
at serialize (./node_modules/mongration/node_modules/bson/lib/bson/bson.js:47:27)
at Query.toBin (./node_modules/mongration/node_modules/mongodb-core/lib/connection/commands.js:146:25)
at Cursor._find (./node_modules/mongration/node_modules/mongodb-core/lib/cursor.js:263:30)
at nextFunction (./node_modules/mongration/node_modules/mongodb-core/lib/cursor.js:576:10)
In particular I'm trying to use an ObjectId in a find:
Error!
I fixed it locally by doing this
It looks very similar to this issue in sails
https://stackoverflow.com/questions/38603529/argument-must-be-a-string-in-nodejs/38606392#comment67911586_38606392