Query specific fields of mongoDB using node.js
mongodb, mongoose, node.js
Solution
If you are using latest nodejs mongodb driver 3.0 or above try this code:
Data.find({}).project({ _id : 1, serialno : 1 }).toArray()
Problem
In the code below the query gives me all the fields. I only want to query _id and serialno. How to go about it. Schema ``` var DataSchema = new Schema({ serialno: String, info: String, active: Boolean, content: String }); ``` Query ``` // Get list of datas exports.index = function(req, res) { Data.find(function (err, data) { if(err) { return handleError(res, err); } return res.json(200, data); }); }; ```