最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Mongoose使用.select()方法

IT培训 admin 6浏览 0评论

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()的情况下做到这一点。

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论