Details
-
Task
-
Resolution: Done
-
Blocker - P1
-
None
-
2.7.2
-
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?