Reputation: 361
I am using sailsjs mongodb and node.js
i am getting error following error in mongodb query please help!
i want to get result of those messages which match Exactly with $all: [ senderID , sendToID ]
this is my document "message" in mongodb.
{ "users": [ "52ed09e1d015533c124015d5", "52ed4bc75ece1fb013fed7f5" ], "user_msgs": [], "createdAt": ISODate("2014-02-04T11:59:53.220Z"), "updatedAt": ISODate("2014-02-04T11:59:53.220Z"), "_id": ObjectID("52f0d639b922c9142763c336") }
now i want to query
Message.find({ users : { $all: [ msg.sender , msg.sendTo ] } }) .done(function (err, detail) { if (err) { console.log(err) } else { console.log( detail)} });
which returns error
{[MongoError:$all requires array] name:'MongoError'}
i am following documentation http://docs.mongodb.org/manual/reference/operator/query/all/ but still have no idea what is causing problem
Upvotes: 2
Views: 398
Reputation: 2416
In Waterline there is not a way currently to query embedded records. You can drop down to the native mongo driver in sails-mongo though and run queries. The following should give you what you need.
User.native(function(err, collection) {
collection.find({ users: {
$all: [ "52ed09e1d015533c124015d5", "52ed4bc75ece1fb013fed7f5" ]
}}).toArray(function(err, docs) {
// Do something here
});
});
Upvotes: 1