Sha*_*gie 4 mongoose mongodb node.js
这是一个非常奇怪的问题,我无法解决。我的查询代码段是这样的:
userTypeModel.find({$or: [{name: 'ADMIN'}, {name: 'SUPERADMIN'}], activeStatus: 1}, function (err, userTypeRow) {
if (err) {
flowController.emit('ERROR', {message: "Unable to Get details! Try again " + err, status: 'error', statusCode: '500'});
} else if (userTypeRow.length == 0) {
flowController.emit('ERROR', {message: "No user-types available in the system yet!", status: 'error', statusCode: '404'});
} else {
var adminId = null;
var superAdminId = null;
async.eachSeries(userTypeRow, function (element, callback) {
if (element.name == 'ADMIN') {
adminId = String(element._id);
}
if (element.name == 'SUPERADMIN') {
superAdminId = String(element._id);
}
callback();
}, function (err) {
if (err) {
flowController.emit('ERROR', err);
} else {
flowController.emit('1', adminId, superAdminId);
}
});
}
});
Run Code Online (Sandbox Code Playgroud)
当我调用此查询时,我得到了响应
{
"message": "ERROR WHILE GETTING USERS Error: Can't use $or with String.",
"status": "error",
"statusCode": "500"
}
Run Code Online (Sandbox Code Playgroud)
我在MongoClient RoboMongo中运行了上述查询,并成功了!以编程方式查询中的问题在哪里?
小智 5
我不知道为什么它实际上不起作用(也许正在看猫鼬),但是如果有人想让这个请求生效,这是一个对我有用的解决方案:
userTypeModel.find({
name : {
$in : [
'ADMIN',
'SUPERADMIN'
]
},
activeStatus : 1 }, function (err, userTypeRow) {...})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2385 次 |
| 最近记录: |