gpt4 book ai didi

mongodb - 从 Meteor 搜索查询中排除 _id?

转载 作者:可可西里 更新时间:2023-11-01 09:13:46 27 4
gpt4 key购买 nike

我正在尝试从没有 _id 字段但也不包含的 Meteor 集合中提取文档:

Db.find({foo: bar}, {fields: {
test1: 1,
test2: 1,
_id: 0
}})

也不排除:

Db.find({foo: bar}, {fields: {
test3: 0,
_id: 0
}})

似乎有效。两者都只返回一个空数组。我知道在 Mongo 中可以提取排除了 _id 的文档,它在 Meteor 中吗?

最佳答案

我想你忘记了一些牙套:

Db.find({
foo: bar
}, {
fields: {
test3: 0,
_id: 0
}
});

我在某处读到,不支持包含/排除的混合。这意味着,您的第一个示例将不起作用。

编辑:

来自 meteor docs :

Field Specifiers

On the server, queries can specify a particular set of fields to include or exclude from the result object. (The field specifier is currently ignored on the client.)

To exclude certain fields from the result objects, the field specifier is a dictionary whose keys are field names and whose values are 0.

Users.find({}, {fields: {password: 0, hash: 0}})

To return an object that only includes the specified field, use 1 as the value. The _id field is still included in the result.

Users.find({}, {fields: {firstname: 1, lastname: 1}})

It is not possible to mix inclusion and exclusion styles.

关于mongodb - 从 Meteor 搜索查询中排除 _id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15193230/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com