[英]How can I get a “clean” list from mongoose queries
I execute a find query of mongoose: 我执行猫鼬的查找查询:
UG.find({ "emailUser": req.body.emailUser }, "nameGroup" ,function (err, groups) {
console.log(groups)
});
The result is "dirty" with some id, 结果是带有某些ID的“肮脏”,
How can I "clean" the result to a simple array -of only "namegroup"? 如何将结果“清理”到仅包含“ namegroup”的简单数组?
id
is always returned by mongodb. id
始终由mongodb返回。 You need to explicitly exclude it. 您需要明确排除它。
UG.find({ "emailUser": req.body.emailUser }, "nameGroup -id" ,function (err, groups) {
console.log(groups)
});
For the _id field, you do not have to explicitly specify _id: 1 to return the _id field. 对于_id字段,您不必显式指定_id:1即可返回_id字段。 The find() method always returns the _id field unless you specify _id: 0 to suppress the field. 除非您指定_id:0来禁止显示该字段,否则find()方法始终返回_id字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.