I am trying to execute the query from my node.js-express application.The query is not returning any result. But when I execute the query in the mongodb shell it shows the expected result.
My code is:
var query = commentModel.Comment.find({
"$and": [
{
"type": {
"$in": [
207,208,209
]
}
},
{
"trs": {
"$ne": 3
}
},
{
"$or": [
{
"status": {
"$in": [
1,
2
]
}
},
{
"$and": [
{
"status": 3
},
{
"UID": req.session.userId
}
]
}
]
}
]
}).skip(this.index).limit(this.count);
console.log("Query : "+ JSON.stringify(query));
query.exec(function(err, result) {
console.log("Result Length :"+result.length+" Error:"+err);
if( (err) || (result.length == 0)) {
console.log("Result Length :"+result.length+" Error:"+err);
}
else {
console.log("Success Result Length :"+result.length+" Error:"+err);
}
});
When I print the query to console
Query : {"options":{"populate":{}},"_conditions":{"$and":[{"type":{"$in":[207,208,209]}},{"trs":{"$ne":3}},{"$or":[{"status":{"$in":[1,2]}},{"$and":[{"status":3},{"UID":14}]}]}]},"_updateArg":{},"op":"find"}
I use the _condition from this and execute it in mongodb shell as
>db.tbl_comment.find({"$and":[{"type":{"$in":[207,208,209]}},{"trs":{"$ne":3}},{"$or":[{"status":{"$in":[1,2]}},{"$and":[{"status":3},{"UID":14}]}]}]})
Here in the shell it displaying the result. I don't know what is missing...