find("_id": {"$oid": "5eb8ebd93e7356145d17273b"}) didn't work.


DataGrip view as json display this:

But when i look for this data like this:

db.xxxx.find("_id": {"$oid": "5eb8ebd93e7356145d17273b"})

It returns an error:

"Query failed with error code 2 and error message 'unknown operator: $oid'

And look for like this can success:

db.xxxx.find({"_id": {"objectId": "5c7934944bbf5f1d900039d9"}})

This is a bug or a special design?
Looking forward to replay!

1 comment
Comment actions Permalink

Hello @291712141 
It's not a bug. It's an extended JSON format
This format allows to save type information

You would get the same value if you run mongoexport tool

MongoDB does not allow you to query using extended JSON.
Neither `{"$oid": "5eb8ebd93e7356145d17273b"}` nor `{"objectId": "5c7934944bbf5f1d900039d9"}` will succeed in mongo shell and in DataGrip. You should use different syntax: `{"_id": ObjectId('5eb8ebd93e7356145d17273b')}`

IDE can generate this filter for you
You can open a Table View and in context menu find Filter By


Please sign in to leave a comment.