Query like Mongodb query


I am trying to query like mentioned in https://www.mongodb.com/docs/manual/reference/operator/query/regex/#mongodb-query-op.-regex

When I try using
GET “http://localhost:8400/api/content/items/Books?filter={Code:/^BG-/}&populate=1

It does not return any valid response.

Any suggestions?

Best regards

Hi JB,
I am assuming its a public accessible API, so no token required.
It seems you want to filter out every document which has the field “Code” and its content starts with “BG-”.
http://localhost:8400/api/content/items/Books?filter={Code: {$regex: “/^BG-/”}}&populate=1

Hi there,

I found some solution. It would be great if someone can elaborate a bit.

GET “http://localhost:8400/api/content/items/Books?filter={Code:{‘$regex’:‘/^BG-/’}}&populate=1”

with OR

GET “http://localhost:8400/api/content/items/Books?filter={ ‘$or’: [ {‘Code’ : {‘$regex’ : ‘/^G-H/’}}, {‘Code’ : {‘$regex’ : ‘/^G-E/’}}]}&populate=1” works

thanks. I also figured out. Could you share how to use other tags in mongo query.

I am sorry but I am not sure what you mean with “other tags”.

I am referring to list of Query Selectors in https://www.mongodb.com/docs/manual/reference/operator/query/

unfortunately not.
I found the solution to regex a while ago and could share this quickly :slight_smile:

anyway, thanks a lot.