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);
});
我想要实现的只是从数据库中的事务中选择具有该用户名的事务,我只想取出 select
方法中列出的字段.谁能指出我应该如何使用 select
方法?谢谢.
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 说你可以这样实现:
猫鼬 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()
也能做到这一点.
so you can do this without select()
.
这篇关于Mongoose 使用 .select() 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文