I have the following code:
var objectid = infos[i].id; var name = infos[i].name; return collection.aggregate([ {$match: {app: new ObjectId(objectid)}}, {$group: {_id: "$uid", amt: {$sum: 1}}} ])
This code used to work fine before, but lately I started getting the bottom stack in sails:
error: TypeError: Argument must be a string at TypeError (native) at Buffer.write (buffer.js:791:21) at serializeObjectId (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:242:10) at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:699:17) at serializeObject (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:280:18) at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:705:17) at serializeObject (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:280:18) at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:551:17) at serializeObject (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:280:18) at serializeInto (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/parser/serializer.js:705:17) at serialize (/Users/user/git/pivot/code/node_modules/sails-mongo/node_modules/bson/lib/bson/bson.js:47:27)
It complains about the ObjectId , which I imported like this:
var ObjectId = require('mongodb').ObjectID;
As I said, this works fine, but no longer works. I'm really confused. If I put objectId in a string, it will not return any results. If I leave it as it is (since it worked before), it throws exceptions. What is the problem?
I read below:
https://docs.mongodb.com/v3.0/reference/operator/aggregation/cmp/#exp._S_cmp
I can do it in robomongo:
db.getCollection("openevent").aggregate([ {$match: {app: new ObjectId(OBJECT_ID) }}, {$group: {_id: "$uid", amt: {$sum: 1}}} ])
Using the same values as above. What am I doing wrong?
I see the following for sails-mongo :
└─┬ sails-mongo@0.12.1 └─┬ mongodb@2.1.6 └── mongodb-core@1.3.1