Announcement Announcement Module
Collapse
No announcement yet.
[Mongo] Creating a BasicQuery using a string containing regex Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • [Mongo] Creating a BasicQuery using a string containing regex

    Hi,

    I am trying to query mongo via springdata mongoTemplate.find(Query,<T>) method. I am passing a BasicQuery object created using a string containing the appropriate query. If I try the query directly on the mongo shell it works fine, but it throws a JSON parser exception when used via the BasicQuery object. the query string looks like the following:

    { $or: [ {user1: {id: "102", type: "USER"}}, {user2: {id: "102", type: "USER"}}], message: {$in: [/.*Test.*/,/.*keyword1.*/]}}

    I get the following exception:

    com.mongodb.util.JSONParseException:
    { $or: [ {user1: {id: "102", type: "USER"}}, {user2: {id: "102", type: "USER"}}], message: {$in: [/.*Test.*/,/.*keyword1.*/]}}
    ^
    at com.mongodb.util.JSONParser.parse(JSON.java:198)
    at com.mongodb.util.JSONParser.parseArray(JSON.java:5 39)
    at com.mongodb.util.JSONParser.parse(JSON.java:191)
    at com.mongodb.util.JSONParser.parseObject(JSON.java: 231)
    at com.mongodb.util.JSONParser.parse(JSON.java:195)
    at com.mongodb.util.JSONParser.parseObject(JSON.java: 231)
    at com.mongodb.util.JSONParser.parse(JSON.java:195)
    at com.mongodb.util.JSONParser.parse(JSON.java:145)
    at com.mongodb.util.JSON.parse(JSON.java:81)
    at com.mongodb.util.JSON.parse(JSON.java:66)
    at org.springframework.data.mongodb.core.query.BasicQ uery.<init>(BasicQuery.java:35)


    can somebody kindly guide me as to how I can get this working?
Working...
X