我使用的MongoDB和猫鼬用的NodeJS(表达),一切工作正常,除了这个功能:猫鼬按字段查找?
router.get('/', function(req, res, next) {
promotions.find({active:"true"},function(err,promo){
if (err) throw err;
res.render('index',
{
promos: promo
});
});
});
它带回在促销空数组,但我有文件在我的数据库。
该问题似乎与“{active:”true“}”中的字段激活有关。当我查找没有任何过滤器的文档时(使用“find({},...”)它工作正常。
当我运行mongo中的db.promotions.find({active:“true”}) 。
这是我的推广模式:
// grab the things we need
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
// create a schema
var promotionSchema = new Schema({
title: String,
subtitle: String,
url: String,
image: String,
active:
{
type: Boolean,
default: false
}
});
var Promotion = mongoose.model('Promotion', promotionSchema, 'promotions');
// make this available to our Node applications
module.exports = Promotion;
这是我在MongoDB中得到:
我试过{active:true}({“active”:“true”},{“active”:true})等各种可能的格式,并且没有任何效果。
我认为db.Promotions.find()将返回空!核实! –