Regex in data api not working

I tried to filter with a regex, it works in Compas : { “area” : /.no se que./ }
but when I tried with the data api I needed to put quotes
as this : {“area” : “/.no se que./”} .

Do anyone knows how can I resolve this problem?
Regards

As far as I know the short-cut syntax // is only available in JS.

Try using the full syntax that uses $regex.

1 Like

Hi, I already tried with the same results
{“area”: {"$regex": /.no se que./}} working
{“area”: {"$regex": “/.no se que./”}} not working

Any other idea?

Hi @Brahian_Velazquez and welcome in the MongoDB Community :muscle: !

This works for me against the sample_mflix.movies database from the sample data sets in Atlas.

curl --location --request POST 'https://data.mongodb-api.com/app/data-utkat/endpoint/data/beta/action/find' --header 'Content-Type: application/json' --header 'Access-Control-Request-Headers: *' --header 'api-key: clZkRovvPtdfHLVFwvUTMfsqapKsGU9eNoUkcM83vdQB1P1DFfEI57qtwcGJDeSv' --data-raw '{
    "collection":"movies",
    "database":"sample_mflix",
    "dataSource":"Free",
    "filter": {"title": {"$regex": "Matrix"}},
    "projection": {"_id":0, "title":1}
}'

The same filter in Compass returns 4 docs.

{"documents":[{"title":"The Matrix"},{"title":"The Matrix Reloaded"},{"title":"The Matrix Revolutions"},{"title":"Armitage: Dual Matrix"}]}

See the doc of $regex if you need options.

Cheers,
Maxime.

4 Likes

yes, is working now , thanks

3 Likes

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