Mongodb find() 查询中的限制字段不起作用 [英] Limit Field in Mongodb find() query not working
问题描述
我有一个包含以下字段的 MongoDB 数据库:
I have a MongoDB database withe the following fields:
idSite: 3
parentHash: "zz"
siteDesc: "Second Site"
siteHash: "ab"
siteLevel: "1"
siteName: "Riotech"
siteType: "Company"
idSite: 4
parentHash: "zz"
siteDesc: "Oregon City Site"
siteHash: "aa"
siteLevel: "1"
siteName: "iTi"
siteType: "Company"
我想编写一个带有投影的查询,将结果限制为一个字段的数据集,parentHash
.当我编写以下查询时:Sites.find({"siteHash":"aa"},{parentHash:1})
.
I want to write a query with a projection that limits the result to a dataset of one field, parentHash
. When I write the following query: Sites.find({"siteHash":"aa"},{parentHash:1})
.
我得到以下结果:
idSite: 4
parentHash: "zz"
siteDesc: "Oregon City Site"
siteHash: "aa"
siteLevel: "1"
siteName: "iTi"
siteType: "Company"
我试过用双引号和单引号包装字段名称,不带引号.我尝试将所有其他字段的返回状态定义为 false.一切都会返回完整的文档.
I have tried wrapping field names with double and single quotes, without quotes. I have tried defining the return status of all the other fields as false. Everything returns the full document.
推荐答案
我觉得应该是 Sites.find({"siteHash":"aa"},{fields: {parentHash:1}});
http://docs.meteor.com/#/full/find
这篇关于Mongodb find() 查询中的限制字段不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!