Mongoose retrieving data without _id field

前端 未结 4 1396
挽巷
挽巷 2020-12-04 21:31

I would like to retrieve some data from a Mongoose setting in my Node.js application. I noticed that no matter what I write as field selection, I always get the _id

4条回答
  •  难免孤独
    2020-12-04 21:37

    _id must be specifically excluded. For example,

    Transaction.find({username : user.username}, { '_id': 0, 'uniqueId' :1, 'timeout': 1, 'confirmation_link': 1, 'item_name': 1}, function(err, txs){
      console.log("user : " + user.username + " with txs: " + txs);
      callback(txs);
    });
    

提交回复
热议问题