0

I have this data in my database.

"_id" : ObjectId("5c1b34d11aa970061a76aa68"),
        "city" : "Delhi"

I tried to get city like this.

 db.myCollection.find({_id:ObjectId("5c1b34d11a970061a76aa68")},{_id:0,city:1})

I am getting output { "city" : "Delhi" } like this. but i need only Delhi without quotes and "city". Is it possible.

1

2 Answers 2

1

Use toArray() and map()

db.myCollection
    .find({_id:ObjectId("5c1b34d11a970061a76aa68")},{ _id:0, city:1 })
    .toArray()
    .map(function(result){ return result.city;})
Sign up to request clarification or add additional context in comments.

Comments

0
db.myCollection.find({_id:ObjectId("5c1b34d11a970061a76aa68")},function(err,result){
 res.render('yourviewpath', {
        response: result
    });

});
in view you can access like tbis as i am using ejs <%=response.result.city=>

it will print only city

1 Comment

I don't want to print. I need to take that result to frontend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.