Mongoose使用.select()方法
我对使用select
方法很困惑。这就是我使用它的方式,这是错误的:
Transaction.find({username : user.username}).select('uniqueId', 'confirmation_link', 'item_name', 'timeout', 'username', function(err, txs){
callback(txs);
});
我想要实现的只是从数据库中的事务中选择具有该用户名的事务,我想只取出select
方法中列出的字段。任何人都可以指出我应该如何使用select
方法?谢谢。
docs说你可以这样做:
猫鼬vh.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()方法
我对使用select
方法很困惑。这就是我使用它的方式,这是错误的:
Transaction.find({username : user.username}).select('uniqueId', 'confirmation_link', 'item_name', 'timeout', 'username', function(err, txs){
callback(txs);
});
我想要实现的只是从数据库中的事务中选择具有该用户名的事务,我想只取出select
方法中列出的字段。任何人都可以指出我应该如何使用select
方法?谢谢。
docs说你可以这样做:
猫鼬vh.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()
的情况下做到这一点。