从 mongo 结果中删除 _id [英] remove _id from mongo result

查看:64
本文介绍了从 mongo 结果中删除 _id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 mongo 和 nodejs 还很陌生我有一个 json 作为查询的结果,我只想将结果作为 http 请求返回,如下所示:

I'm pretty new with mongo and nodejs I've a json as result of my query and I simply want to return the result as an http request, as following:

app.get('/itesms', function(req, res) {
  items.find().toArray(function (err, array) {
    res.send(array);
  })
});

它有效,唯一的问题是我想从结果中隐藏 _id 字段(递归).有什么建议可以优雅地做到这一点吗?

It works, only problem is that I want to hide the _id fields (recursively) from the result. Any suggestion to do that in an elegant way?

推荐答案

试试这个解决方案:

app.get('/itesms', function(req, res) {
  items.find({}, { _id: 0 }).toArray(function (err, array) {
    res.send(array);
  })
});

这篇关于从 mongo 结果中删除 _id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆