问题描述
我尝试检索/填充已经存在的猫鼬文档的属性?
我不想在初始查找查询中投影键,因为我仅在1%的呼叫中使用该属性...
有什么主意吗?看来填充仅适用于交叉收藏夹引用。
非常感谢!
解决方法
如果我理解正确,您是否想使用猫鼬ORM在MongoDB(我想是?)数据库中检索文档?
一些功能:
your_mongoose_schema.findOne({your_column: "column1"},function(err,doc) {
//return the first document that have column1 for your_column attributes
// doc.your_column = "column1"
})
your_mongoose_schema.find({your_column: "column1"},docs) {
//docs = array with all the docs that have "column1" for your_column attributes
})
如果要检索不带_id属性的文档:
your_mongoose_schema.find({your_column: "column1"},{ '_id': 0,'column1' :1},doc){
});