Mongoose使用.select()方法 [英] Mongoose use of .select() method
本文介绍了Mongoose使用.select()方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对使用 select
方法感到困惑。这就是我使用它的方式,这是错误的:
I'm pretty confused with the use of the select
method. This is how I use it, and it's wrong:
Transaction.find({username : user.username}).select('uniqueId', 'confirmation_link', 'item_name', 'timeout', 'username', function(err, txs){
callback(txs);
});
我想要实现的只是从数据库中的事务中选择具有该事务的事务用户名和我想要只取出选择
方法中列出的字段。任何人都可以指出我应该如何使用选择
方法?谢谢。
What I'm trying to achieve is simply to select from the transactions in the database the ones with that username and I want to take out just the fields listed in the select
method. Can anyone point out how should I use the select
method? Thanks.
推荐答案
docs 说你可以这样做:
Mongoose v4.0
// Retrieving only certain fields
Model.find({}, 'first last', function (err, docs) {
});
旧的过时API
// Retrieving only certain fields
Model.find({}, ['first', 'last'], function (err, docs) {
// docs is an array of partially-`init`d documents
// defaults are still applied and will be "populated"
});
所以你可以不用 select()
。
这篇关于Mongoose使用.select()方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文