[英]deep find() query in Mongoose
so my schema looks like something like this 所以我的架构看起来像这样
var PagesSchema = new mongoose.Schema({
citiesList:{
country:String,
city:String
}
});
i want to access citiesList in my route so i tried 我想访问路线中的citysList,所以我尝试了
app.get("/", function(req,res){
Pages.find({"citiesList"}, function(err,citiesList){
if(err){
console.log(err);
}else{
res.render('landing',{citiesList:citiesList});
}
});
});
but it's not working any advice please ? 但是它没有任何建议吗?
That query is searching for any document that look like {citiesList: "citiesList"}
. 该查询正在搜索看起来像
{citiesList: "citiesList"}
任何文档。 If you want all "citiesList", you can instead use {}
to find all documents, and a projection to limit it to the citiesList
field: Pages.find({}, "citiesList", cb)
如果需要所有 “ citiesList”,则可以改用
{}
查找所有文档,并使用投影将其限制在“ citiesList
字段中: Pages.find({}, "citiesList", cb)
https://mongoosejs.com/docs/api.html#model_Model.find https://mongoosejs.com/docs/api.html#model_Model.find
If instead you want only those subdocuments in a formatted list, you can use an aggregation to process them 相反,如果只希望格式化列表中的那些子文档,则可以使用聚合来处理它们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.