gpt4 book ai didi

node.js - Mongoose 错误 : Can't use $or with String

转载 作者:可可西里 更新时间:2023-11-01 09:12:54 26 4
gpt4 key购买 nike

这是一个非常奇怪的问题,我无法修复它。我的一段查询代码是这样的:

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);
}
});
}
});

当我调用这个查询时,我得到的响应是

{
"message": "ERROR WHILE GETTING USERS Error: Can't use $or with String.",
"status": "error",
"statusCode": "500"
}

我在 MongoClient RoboMongo 中运行了上面的查询并且成功了!以编程方式查询中的问题在哪里?

最佳答案

我不知道为什么它不起作用(可能在看 mongoose )但是如果有人想让这个请求工作,这里有一个适合我的解决方案:

userTypeModel.find({
name : {
$in : [
'ADMIN',
'SUPERADMIN'
]
},
activeStatus : 1 }, function (err, userTypeRow) {...})

关于node.js - Mongoose 错误 : Can't use $or with String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45842338/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com