如何在mongodb .find中使用变量作为字段?

时间:2018-02-08 08:52:19

标签: node.js

我在mongodb的数据:

{
    "_id" : "5a5ffef0869422169c7aa01b",
    "name" : "Some One", 
    "time" : "2018-1-31 11:59"
}

我有一个查询命令

test.find({"time":"2018-1-31 11:59"}).toArray(function (err,data) {
                    if (err) throw err;
                    console.log(data);
                });

我希望检索作为变量传递的字段时间的数据查询。

但它不起作用:

 // my code ....
    var input = yy +"-"+mm+"-"+dd+" "+hh+":"+minute;
    var text = "time";
    test.find({ text : input }).toArray(function (err,data) {
                if (err) throw err;
                console.log(data);
            });

如何查询mongodb,同时保持字段名称及其值的动态?

0 个答案:

没有答案