0

I have created one table. example

use abc

db.test.create( {rollid: 4451, Name : "MongoDb"}, {rollid: 4452, Name : "casandra"})

Now i need only one filed value without id.

I tried with the below query but id also displayed.

db.test.find({},{Name : "Mongodb"})

Here i received the output

{ "_id" : ObjectId("5bec88847825b85d854cd6e3"), "Name" : "MongoDb" }

But i don't need combination of "_id" and Name. I need only Mongodb name.

How can i retrieve only one filed value without id?

Ramesh
  • 1
  • 7

2 Answers2

0

You can try this:

db.test.find({}, { _id: 0 }).toArray()

OR

db.test.find({}, { _id: 0 }).toArray(function(err, array) {
  // Do something with array
  console.log(array);
})
Arslan Khan
  • 385
  • 3
  • 6
  • 1
    i got the solution. Thanks for the response. db.test.find({},{"Name" : "MongoDb", "_id" : 0}) – Ramesh Jan 07 '19 at 21:47
0

See: See: https://docs.mongodb.com/manual/reference/method/db.collection.find/#find-projection

db.test.find({Name: "MongoDb"}, {_id: 0})
wlh
  • 3,426
  • 1
  • 16
  • 32
  • i got the solution. Thanks for the response. db.test.find({},{"Name" : "MongoDb", "_id" : 0}) – Ramesh Jan 07 '19 at 21:48