Mongoose use of .select() method

前端 未结 9 1653
孤城傲影
孤城傲影 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:47

    Select method is used to select which fields are to be returned in the query result, excluding select means we want all the fields to be returned, here is simple usage as per the docs.

    // include a and b, exclude other fields  
    query.select('a b');
    
    // exclude c and d, include other fields  
    query.select('-c -d');
    

    More information here, https://mongoosejs.com/docs/api.html#query_Query-select

提交回复
热议问题