在我的本地主机/列表页面上,我的GET正在显示
[{"_id":"5756f1aa64fa4d3104f98f89","mcr":"relationship","info":{"test":"test"}}]
但我想只返回
[{"info":{"test":"test"}}]
我的find函数在mongo命令行上运行正常,它返回预期的内容。:
db.usercollection.find({},{"_id":0,"mcr":0})
但是,在我的JS文件中调用时,它不会过滤掉查询。我正在使用express和monk以及MongoDB。这是我的router.get:
router.get('/list', function(req, res) {
var db = req.db;
var collection = db.get('usercollection');
collection.find({},{"_id":0,"mcr":0},function(e,docs){
res.json(docs);
});
});
不会抛出错误,状态代码为200,问题是什么?我在find函数中尝试了很多变化,但没有任何运气。
答案 0 :(得分:0)
我发现了这个问题,显然mongo还没有完全更新他们的文档。我需要使用{fields:{_ id:0}}。
最终代码:
router.get('/list', function(req, res) {
req.db.get('usercollection').find({},{fields: {"_id":0,"mcr":0}},function(e,docs){
res.json(docs);
//console.log(docs);
});
});