gpt4 book ai didi

javascript - mongodb-如何从此查询中隐​​藏 _id ?

转载 作者:行者123 更新时间:2023-12-03 00:59:32 24 4
gpt4 key购买 nike

如何从此查询中隐​​藏 _id,我使用 Express Node.js ?

我有这个查询,我创建了一个 API,但我想隐藏 _id。

这是查询:

router.get("/", (req, res) => {
VerbsDE.find({}, { _id: 0 })
.limit(1)
.then(verbs => {
res.send(verbs);
});
});

///////////////////////////////////////////////////////////////////////////////////////////这是集合:

[
{
Indicative: {
Present: [
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
}
],
Perfect: [
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
}
],
Past: [
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
}
],
Pluperfect: [
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
}
],
Future_I: [
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
}
],
Future_II: [
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
}
]
},
Imperative: {
Worte: [
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
},
{
_id: "5bb9009249efde355376ad29",
pron: "xxx",
verb: "xxx xxx xxx"
}
]
},
_id: "5bb9009249efde355376ad23",
verbName: "abbilden",
__v: 0
}
];

我尝试隐藏 _id ,但每次出错时,我想获取数据但不使用 Id 。

最佳答案

您可以尝试使用投影( https://docs.mongodb.com/manual/reference/method/db.collection.find/ ):

{projection: { _id: 0 }}

如:

router.get("/", (req, res) => {
VerbsDE.find({}, {projection: { _id: 0 }})
.limit(1)
.then(verbs => {
res.send(verbs);
});
});

关于javascript - mongodb-如何从此查询中隐​​藏 _id ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52686976/

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