Mongoose use of .select() method

前端 未结 9 1649
孤城傲影
孤城傲影 2020-12-14 14:16

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}).sele         


        
9条回答
  •  攒了一身酷
    2020-12-14 14:40

    the docs say you can achieve this like so:

    Mongoose v4.0

    // Retrieving only certain fields
    
    Model.find({}, 'first last', function (err, docs) {
    
    });
    

    old outdated 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"
    });
    

    so you can do this without select().

提交回复
热议问题