Mongolite substring query

127 Views Asked by At

In my collection I want to filter out all documents having a title that starts with "Once". Implementing this query in MongoDB Compass works fine

query = '{"title" : /^((?!Once).)/i }'

but trying to do the same in R with mongolite returns the error:

Invalid JSON object.

What do I need to change?

1

There are 1 best solutions below

0
On BEST ANSWER

I believe in Mongolite you can avoid that error using MongoDB's $regex with " instead of \ :

query = '{"title": {"$regex": "^((?!Once).)" , "$options": "i"}}'