Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Data Science
  3. Question
Data Science

Mongoose, Select a specific field with find

Asked by Hasegawa Saito Jul 14, 2021 2.2K views 1 answer
Share

About this question

I want to select only a particular field with the help of the following code:

exports.someValue = function(req, res, next) {
    //query with mongoose
    var query = dbSchemas.SomeValue.find({}).select('name');
    query.exec(function (err, someValue) {
        if (err) return next(err);
        res.send(someValue);
    });
};

But in my JSON, I am receiving the _id also, my document schema only has two fields, _id and name

[{"_id":70672,"name":"SOME VALUE 1"},{"_id":71327,"name":"SOME VALUE 2"}]

Can anybody explain me why I am getting this error?and how mongoose select fields ?

Your answer

1 Answer

More Data Science discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Data Science Blogs

Guides, tips and career advice on Data Science from JanBask experts.