How Apply ObjectId filter for Filter Incoming Queries

String filter works correctly but when I try to apply { branch: “634aeffdbccd9d0f6297bb62” } it does not work and returns null.

How to apply filter for ObjectId type?

Hello @Donis_Rikardo, Welcome to the MongoDB community forum,

It would be helpful if you provide more details,

  • Where you are executing your query?
  • What do you mean by String filter?
  • Share the example document that you have in your collection
  • Share your expected result

I am not too sure, but I think you need to use EJSON syntax to make sure the string "634aeffdbccd9d0f6297bb62" is processed as an ObjectId. So I would try:

{ "branch" : { "$oid" : "634aeffdbccd9d0f6297bb62" } }
1 Like

Thanks. There is zero info about that in the documentation.

I got the $oid part from the examples.

1 Like

Thanks. I’m blind. Or it was another docs

Your not. Little details like that are easily skipped.

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