我有这个查询代码但是有问题使它工作。我使用的是NodeJS,数据库是mongoDB。
Transducer.find({$and: [{isNew:{$eq:true}}, {isPublished:{$eq:true}}]})
.sort({"nominalDiameterin":1})
.limit(50)
.exec(function(err, allTransducers){
if(err) {
throw err;
} else {
if(req.xhr) {
res.json(allTransducers);
} else {
var id = req.params.id;
if(id === 'en'){
res.render("products/transducers", {transducers: allTransducers, length: allTransducers.length});
}else if(id === 'cn'){
res.render("products/transducers-cn", {transducers: allTransducers, length: allTransducers.length});
}
}
我想显示新的和已发布的数据,但我没有运气。
请帮忙吗?
答案 0 :(得分:0)
亲爱的@Vina Vanessa Compson你不需要使用$和$ eq运算符进行简单查询,你的语法也不正确。
请按照以下答案
var query = {
isNew:true,
isPublished:true
}
var toSort = {
nominalDiameterin:1
}
Transducer.find(query).sort(toSort).limit(50).exec(function(err, allTransducers) {
if (err) {
throw err;
} else {
if(req.xhr) {
res.json(allTransducers);
} else {
var id = req.params.id;
if(id === 'en'){
res.render("products/transducers", {transducers: allTransducers, length: allTransducers.length});
}else if(id === 'cn'){
res.render("products/transducers-cn", {transducers: allTransducers, length: allTransducers.length});
}
}
}
})