Mongoose 在没有 _id 字段的情况下检索数据 [英] Mongoose retrieving data without _id field
本文介绍了Mongoose 在没有 _id 字段的情况下检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从我的 Node.js 应用程序中的 Mongoose 设置中检索一些数据.我注意到无论我写什么作为字段选择,我总是得到 _id
字段.有没有办法不取?这就是我现在的做法:
I would like to retrieve some data from a Mongoose setting in my Node.js application. I noticed that no matter what I write as field selection, I always get the _id
field. Is there a way not to fetch it?
This is how I do right now:
Transaction.find({username : user.username}, ['uniqueId', 'timeout', 'confirmation_link', 'item_name'], function(err, txs){
console.log("user : " + user.username + " with txs: " + txs);
callback(txs);
});
并记录包含 _id
字段的结果.
And logs me the results which contain the _id
field.
推荐答案
_id
必须特别排除.例如,
_id
must be specifically excluded. For example,
Transaction.find({username : user.username}, { '_id': 0, 'uniqueId' :1, 'timeout': 1, 'confirmation_link': 1, 'item_name': 1}, function(err, txs){
console.log("user : " + user.username + " with txs: " + txs);
callback(txs);
});
这篇关于Mongoose 在没有 _id 字段的情况下检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文