I'm trying generate a list of user ids which I want to use to find them in a mongodb collection.
If I do the following I get an error on the 3rd line saying: "undefined is not a function".
var ids = [];
for (var i = 0; i < item.users.length; i++) {
ids.push(new BSON.ObjectId(item.users[i].appProfileId));
}
db.collection('users', function(err, collection) {
collection.find({_id: {$in: ids}}, function(err, users) {
if (err) {
console.log(err);
} else {
console.log("USERS to push to: " + JSON.stringify(users));
pusher(users, from, channelId);
}
});
});
If I use the answer form here: Mongo, find through list of ids it says that ObjectId is undefined and it crashes. If that is the only solution, how to I define ObjectId for that solution to work?
EDIT:
var ids = [];
for (var i = 0; i < item.users.length; i++) {
ids.push(item.users[i].appProfileId);
}
console.log("ids: " + JSON.stringify(ids));
results in:
"ids": [
"535cf8e3df3aaa723fc9cad1",
"535cf8e3df3aaa723fc9cad1",
"535cf8e3df3aaa723fc9cad1"
]
But since crash happens when I use BSON I can't see anything in ids. And if I search for this list the result is empty. Because of the missing BSON.ObjectId I guess since this search works for a single object.