Find by second field if first field not found

Is it possible to find documents by second field if not found by first field?

For example:
In a document we have “productName” and “brand” fields:

[
  { productName: "red box", brand: "tiny boxes" },
  { productName: "green box", brand: "tiny boxes" },
  { productName: "red blue box", brand: "big boxes" },
]

First scenario: Search string is “red”. It must return two objects.
Second scenario: Search string is “big”. It must return one object.

Hi @Hadi_N_A,

What about $or condition?

Thank you @ turivishal. It works.
find({ $or: [{ name: { $regex: query, $options: 'i' } }, { brand: { $regex: query, $options: 'i' } }] })

1 Like

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