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
field. Is there a way not to fetch it? This is how I do right now:
Transaction.find({username : user.username}, ['uniqueId', 'timeout', 'confirmation_link', 'item_name'], function(err, txs){ console.log("user : " + user.username + " with txs: " + txs); callback(txs); });
And logs me the results which contain the _id
field.
It seems that the default value of the required attributes of each field in mongoose schema is false.
Sep 3, 2019. By default, MongoDB creates an _id property on every document that's of type ObjectId. Many other databases use a numeric id property by default, but in MongoDB and Mongoose, ids are objects by default.
Everything in Mongoose starts with a Schema. Each schema maps to a MongoDB collection and defines the shape of the documents within that collection.
The value of the $in operator is an array that contains few values. The document will be matched where the value of the breed field matches any one of the values inside the array.
Another way is to use text argument with prefix -
which will exclude this or that field from the result:
Entity.find({ ... }, '-_id field1 field2', function(err, entity) { console.log(entity); // { field1: '...', field2: '...' } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With