Answer the question
In order to leave comments, you need to log in
How to get only required fields?
I use mongo native driver for node.js
I need to get only 2 fields, now I implement it like this
return ( async() => {
let res = await collection.findOne({username:userName});
return {
id : res.id,
userName : res.username
};
})();
collection.findOne(query, [fields, [options]], callback);
let res = await collection.findOne({username:userName},{id : true, username : true});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question