2

node.js-express アプリケーションからクエリを実行しようとしていますが、クエリから結果が返されません。しかし、mongodb シェルでクエリを実行すると、期待どおりの結果が表示されます。

私のコードは次のとおりです。

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);
    }
});

クエリをコンソールに出力すると

クエリ: {"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"}

これから _condition を使用し、mongodb シェルで次のように実行します。

>db.tbl_comment.find({"$and":[{"type":{"$in":[207,208,209]}},{"trs":{"$ne":3}},{"$or":[{"status":{"$in":[1,2]}},{"$and":[{"status":3},{"UID":14}]}]}]})

ここではシェルで結果を表示します。何が足りないのかわからない…

4

0 に答える 0