我有一个 mongoDB 查询
test.find({$or : [ {"timeIn":"2018-1-31 11:57"},{"timeIn":"2018-1-31 11:58"},{"timeIn":"2018-1-31 11:59"} ] }, {"email": 1, "_id": 0}).toArray(function (err,data){
if (err) throw err;
console.log(data);
});
如何用数组替换表达式 {"timeIn":"2018-1-31 11:57"},{"timeIn":"2018-1-31 11:58"},{"timeIn":"2018-1-31 11:59"}
。像这样
test.find({$or : [ array ] }, {"email": 1, "_id": 0}).toArray(function (err,data){
if (err) throw err;
console.log(data);
});
最佳答案
尝试$in
,它需要一个值数组来匹配
test.find({timeIn : {$in: ["2018-1-31 11:57","2018-1-31 11:58","2018-1-31 11:59"]} }, {"email": 1, "_id": 0}).toArray(function (err,data){
if (err) throw err;
console.log(data);
});
关于javascript - 将 mongoDB 查询中的表达式替换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48837897/