最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Mongoose使用.select()方法

运维笔记admin21浏览0评论

Mongoose使用.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. 暂无评论