R
R
Rabinzon2015-05-30 17:50:08
JavaScript
Rabinzon, 2015-05-30 17:50:08

How to get the desired value of the desired property in node?

This is how I can get all the contents of the Data

Data.find({}, function (err, ds) {
    console.log(ds);
  })
{
"_id":"55696b8c00ed0cbc25cb9161",
    "name":"1234",
    "description":"4rgsdfgdsfg fgsdfgdsf", 
    "__v":0
}

But I need to display only the value of the name field, that is: 1234
For this, I made a method,
dataschema.methods.goodName = function () {
   console.log(this.get('name'))
}
})

This method does not work where I need.
Tell me how can I get the name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-05-30
@Rabinzon

This is called projection, i.e. you can specify which fields to return:

Data.find( { }, { name: 1, fieldName: 1, id: 0 } , function(err, arr) { ... });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question