javascript - 将 mongoDB 查询中的表达式替换为数组

标签 javascript node.js mongodb

我有一个 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/

相关文章:

javascript - 如何修复 JSON.parse() 命令中不需要的异常

mongodb - 将副本集转换为独立服务器后遇到 MongoDB 警告

mongodb - Morphia MongoDB 检查 null 和不存在的字段

javascript - 从 firebase 检索数据导致未定义

javascript - Angular : Update model from directive

插件的 Javascript 模式?

mongodb - mongoDB 中更新的聚合

javascript - mongodb - 不明白为什么/如何使用 map-reduce

node.js - ES2015 模块无法在 Node.js 和 Babel.js 中工作?

javascript - Node.js 中 JSON 字符串的大小是否有限制?