1

I am trying to execute following query which use a regular expression

BasicQuery b = new BasicQuery("{ description: /\bmanager\b/}");

but it throws com.mongodb.util.JSONParseException

com.mongodb.util.JSONParseException: 
{ description: /manager/}
               ^
    com.mongodb.util.JSONParser.parse(JSON.java:216)
    com.mongodb.util.JSONParser.parseObject(JSON.java:249)
    com.mongodb.util.JSONParser.parse(JSON.java:213)
    com.mongodb.util.JSONParser.parse(JSON.java:163)
    com.mongodb.util.JSON.parse(JSON.java:99)
    com.mongodb.util.JSON.parse(JSON.java:79)

How do I prevent this error

1 Answer 1

2

The /.../ notation for regex isn't valid json. To use regex in a json document like that you need the form { field: { $regex: 'acme.*corp', $options: 'i' } as shown here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.