1

I tried get(selected values) query in mongodb.that query in working fine in mongodb shell .but I tried to run node js it not working it showing all data.how to fix it.

query

db.collection('olc_prod_db_category').find({name: { $nin:['DISCONTINUE', 'LIQUOR MINI']}},{ "_id": 0}).toArray()

Expected ouput:

{ "id" : 3, "name" : "IRISH WHISKEY", "hasSubCategory" : "false", "parentId" : "30" }  

but I got this output:

{
    "_id": "5b4efd6fd53be829188070ca",
    "id": 3,
    "name": "IRISH WHISKEY",
    "hasSubCategory": "false",
    "parentId": "30"
}
mickl
  • 48,568
  • 9
  • 60
  • 89
smith hari
  • 437
  • 1
  • 11
  • 22
  • Try to remove the double quotes around _id as I think it should be a property. Not sure if this makes a big difference in object notation. – Andrei May 08 '19 at 15:12

1 Answers1

1

Use .project cursor method

db.collection('olc_prod_db_category').find(
  { name: { $nin:['DISCONTINUE', 'LIQUOR MINI']}}
).project({ _id: 0 }).toArray()
Ashh
  • 44,693
  • 14
  • 105
  • 132