作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何从此查询中隐藏 _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/
我是一名优秀的程序员,十分优秀!