Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-552

What doesn't JSONParser support the /{regex}/i syntax for regular expressions?

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Done
    • Icon: Blocker - P1 Blocker - P1
    • None
    • 2.7.2
    • API
    • None

    Description

      I need to implement regular expression based search on a collection that exists on my production system. Lets say the collection is called User and the search needs to take place on the Name field. Two use cases are required:

      1. User provides a keyword and all User instances are returned where Name contains the provided keyword. This translates nicely into the query:

      { name :

      { $regex : "simp", $options : "i" }

      }

      The Java code works well for this use case.

      2. User provides a keyword and all User instances are returned where Name does not contain the provided keyword. This needs to translate into the following query:

      { name :

      { $not : /simp/i }

      }

      since $not is not supported with $regex.

      However, I cannot pass a string value containing this query to JSONParser because it throws a parse exception. I understand that they query is not valid JSON but works fine when executed directly from the Mongo console.

      Therefore, the question is, why doesn't JSONParser correctly translate the second query string into a valid DBObject?

      Attachments

        Activity

          People

            Unassigned Unassigned
            manish.in.java Manish
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: