pasanmaduranga
pasanmaduranga

Reputation: 530

Spring com.mongodb.util.JSONParseException

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

Upvotes: 1

Views: 2442

Answers (1)

evanchooly
evanchooly

Reputation: 6233

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.

Upvotes: 2

Related Questions