object ID and Compass

143 views
Skip to first unread message

Liz Hall

unread,
Apr 21, 2017, 4:39:42 PM4/21/17
to mongodb-user
All,

i'm trying to find a document by object ID.

this does not work.  What am I doing wrong?

{ "$oid": "589a8205e4b04157be388130" } 


Rhys Campbell

unread,
Apr 23, 2017, 11:19:02 AM4/23/17
to mongodb-user
Your value for ObjectID is a string not an ObjectID. This will never match. You need to do tis...

{ "$oid": ObjectId("589a8205e4b04157be388130") }  

R

Kevin Adistambha

unread,
Apr 24, 2017, 3:48:47 AM4/24/17
to mongodb-user

Hi Liz,

I understand you are using Compass. I believe you are using MongoDB extended JSON correctly with your $oid query. However, Compass still requires you to specify the _id field, e.g.:

{"_id": { "$oid": "589a8205e4b04157be388130" }  }

As Compass’ query bar is observing a strict JSON format, please ensure that all field names are surrounded by the double quote character.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages