8

I use both robomongo and rockmongo as clients for mongo dbs.. suppose I got a collection called Drivers, then searching by id is quite easy:

db.Driver.find({_id:ObjectId('51118447b38639a960000002')})

I recently installed a mongo plugin for Php Storm, however I couldn't figure out how to search for a document by id.. the above query fails:

enter image description here

Ideas?

abbood
  • 23,101
  • 16
  • 132
  • 246

2 Answers2

14

As per the support forum, you should query as:

{_id: {$oid: '51118447b38639a960000002'}}
Mike
  • 14,010
  • 29
  • 101
  • 161
BatScream
  • 19,260
  • 4
  • 52
  • 68
3
{"_id":ObjectId("51118447b38639a960000002")}
Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
sorma Gupta
  • 107
  • 1
  • 4
  • 1
    This should be the new accepted answer. Using `$oid` no longer works, at least not in DataGrip – Yasha Apr 13 '20 at 14:48