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

BasicDBObject does not allow to create negated regular expression

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.7.2
    • API

    Description

      To create a negating regular expression predicate I essentially need to create the following JSON query:

      { $not : /myregex/ }

      Unfortunately this is not possible with BasicDBObject as its toString() method (which essentially calls JSON.serialize(...)) wraps the value into quotation marks in any case which results in the following output:

      { "$not" : "/myregex/" }

      This is rejected by the driver with the following message:

      error: { "$err" : "invalid use of $not", "code" : 13041 }

      The crucial part is the value being wrapped into quotation marks. So I think the driver should not escape the value for a $not key if it is a String as it usually only works with another operator wrapped into yet another DBObject. Would be also cool if a new BasicDbObject("$not", Pattern.compile("myRegex")) would create the correct representation as well. Currently this creates:

      { $not : { $regex : "myRegex", $options : ""}}

      which is rejected by the driver as well.

      Attachments

        Activity

          People

            Unassigned Unassigned
            oliver.gierke Oliver Gierke
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: