If you are looking for a solution to get only the required fields data from mongoDB, this simple solution can help you without any side effect
Say, you have this data fields in your database
meetingId,
meetingDate,
noticeDate,
title,
agenda,
venue,
notice,
noticeDistribution,
chairedBy,
participants,
minutes,
minutesPreparedBy,
minutesApprovedBy,
minutesDistribuion,
status,
username,
userid
But you need to send only minutes
and minutesApprovedBy
fields, then you can go this way,
yourDB.find({}, {minutes:true, minutesApprovedBy:true})
.then(data=>res.send(data))
.catch(err=>res.send(err))
The field you need, put together with a value to true
as shown above. This will return only those fields (filter) from the database. You can also use findOne({}, {})
where necessary.
Top comments (1)
Full docs for projection are at docs.mongodb.com/manual/tutorial/p...