use*_*310 0 mongoose mongodb node.js
我有一组用户 ID
是否可以使用数组作为参数来查询我的数据库,返回数据库中在我的数组中具有 id 的所有用户对象?
这是我之前的尝试
var array = ['123', '1234', '12345'];
var query = PUser.find({'userID': array});
query.exec(function(err, users_result) {
if (!err) {
console.log('all user objects with the array's IDs', users_result);
}
Run Code Online (Sandbox Code Playgroud)
该$in操作会做的伎俩。
var query = PUser.find({'userID': {$in:array}});
Run Code Online (Sandbox Code Playgroud)