从mongo结果中删除_id [英] remove _id from mongo result
本文介绍了从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屋!
查看全文