【发布时间】:2013-10-07 20:31:57
【问题描述】:
我正在尝试使用 mongoose 中的选择运算符为以下对象选择某些字段:
{
"_id" : ObjectId("5249bb97a5de48bda3000003"),
"id": 1,
"geometry" : {
"coordinates" : [
1,
1
],
"type" : "Point"
},
"properties" : {
"TYPE" : "Some Type",
"TIMESTAMP": ......
},
"type" : "Feature"
}
我想 mongo 只返回 'properties.TYPE' 和 properties.TIMESTAMP 字段。我可以使用以下查询在 mongo 中执行此操作:
db.features.find({id: 1}, {'properties.TYPE': 1, 'properties.TIMESTAMP': 1})
我正在尝试使用 mongoose 中的 select 语句来做同样的事情: 变量字段 = { 属性:{ OBJECTID:1,TIMESTAMP:1 } } var query = Feature.find({id: 1}).select(fields);
Mongo 在尝试这样做时会引发错误,因此我不确定 mongoose 是否正确格式化嵌套字段对象。
这是正确的做法吗?
【问题讨论】: