简体   繁体   English

如何从猫鼬查询中获得“干净”列表

[英]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.

相关问题 如何从 mongoose 中的架构中获取值? - How can i get values from my schema in mongoose? "<i>How can I make queries inside a map function async?<\/i>如何在地图函数中进行异步查询?<\/b> <i>- Mongoose<\/i> - 猫鼬<\/b>" - How can I make queries inside a map function async? - Mongoose Mongoose/MongoDB:我如何才能只 $inc 我从数组中获得的第一个值? - Mongoose/MongoDB: How can I $inc only the first value I get from an array? 无法获取Twitterlib fetchtweets()以从列表返回查询 - Can't get Twitterlib fetchtweets() to return queries from a list 如何从节点 express mongoose mongoDb 中的地理位置数据中获取城市名称 - How can I get city name from geolocation data in node express mongoose mongoDb Mongoose - 如何查找并列出链接到另一个的集合? - Mongoose - How can I find and list a collection linked to another? Mongoose Express.js 从多个查询中获取结果 - Mongoose Express.js get result from multiple queries 有没有办法我可以在 mongoose 中修复这个登录代码多个查询 - Is there a way i can fix this login code multiple queries in mongoose 如何获得猫鼬分组数据的总和 - How can I get sum of grouped data with mongoose 如何将两个猫鼬查找查询提交到正确的GET路由? - How to submit two mongoose find queries to the proper GET route?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM