Querying against ObjectId on mongodb

When I run the following query in Robo3T against my collection, it returns a result just fine:
db.getCollection(‘data’).find({ $or: [ {"_id": ObjectId(“5f6b890ac9e77c0008292cc6”) } ] })

However, when I insert the following into the Query box of the MongoDB Reader, I get the below error:

{ $or: [ {"_id": ObjectId(“5f6b890ac9e77c0008292cc6”) } ] }

ERROR MongoDB Reader 0:88 Execute failed: Cannot parse query: { $or: [ {"_id": ObjectId(“5f6b890ac9e77c0008292cc6”) } ] }

The node works fine if I leave the Query box blank. This is my first flow against MongoDB, can anyone tell me what I’m doing wrong?

Hi,
Can you try with this query instead?

{ $or: [ {"_id": {$oid: "5f6b890ac9e77c0008292cc6"} } ] }

Our node uses https://jongo.org to do the queries but supports only plain JSON. According to this post on StackOverflow it might work with the $oid object type.
Kind regards,
Alexander

2 Likes

thanks, that format of the query worked.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.