我正在尝试使用像这样的mongoose在mongodb中运行查询:
mongooseModel.find()。where(query).exec(function(err,data){
});
查询的值是:
{plate:'BCF 5579',fuel_level:{$ lte:20}}
在mongodb日志中,查询将为空({})。
如果我用这样的实际值替换查询:
mongooseModel.find()。where({plate:'BCF 5579',fuel_level:{$ lte:20}})。exec(function(err,data){
});
确实有效。第一个选项出了什么问题?
以下是完整代码:
this.findAllByCondition = function (query, options, callback) {
localLogger.debug('findAllByCondition');
try {
var sortBy = "_id"; // default sort order
var pagingOptions = {
skip: 0,
limit: 30
};
if (options && options.limit) {
pagingOptions.limit = options.limit;
}
if (options && options.skip) {
pagingOptions.skip = options.skip;
}
if (options && options.sortBy) {
sortBy = options.sortBy;
}
if (options && options.sortOrder && options.sortOrder === "desc") {
sortBy = "-" + sortBy;
}
//{ plate: 'BCF 5579', fuel_level: { $lte: 20 }};
//query1 = query;
//query = req.query['q'];
//var query1 = { plate: 'BCF 5579', fuel_level: { $lte: 20 }}
var totalRecords = null;
var results = null;
async.parallel(
[
function (callback) {
mongooseModel.find(query).skip(pagingOptions.skip).limit(pagingOptions.limit).sort("field " + sortBy).exec(function (err, data) {
if (err) {
callback(err);
}
else {
results = data;
callback();
}
});
},
function (callback) {
mongooseModel.count(query, function (err, count) {
if (err) {
callback(err);
}
else {
totalRecords = count;
callback();
}
});
}
],
function (err) {
callback(err, results, totalRecords);
}
);
} catch (exception) {
localLogger.error('exception while trying to findOne ' + exception.message + " stack:" + exception.stack);
callback(exception, null);
}
},