[JAVA-914] $in query with $regex doesn't work Created: 01/Aug/13 Updated: 11/Jun/18 Resolved: 04/Dec/13 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | nirav | Assignee: | Trisha Gee |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
I am trying to write $in query with $regex in mongo+java. It's not working in mongo shell either. What I mean is I don't get any results but no query parse error either. Here's the final query I got from Java Debugger at the line where I say collection.find(finalQuery)
Java Code snipet for Above query: Set businesses = new HashSet();
However, following query works in mongo shell but I don't know how to write it into java: {"registering_organization" : {"$in":[/^.*cardinal.*health.*$/,/^.*the.*hartford.*$/]}} Java Code add double quotes around regex if we try to define it as a string. For workaround, I can do as someone suggested on StackOverflow using Or in my regex. http://stackoverflow.com/questions/17984750/mongodb-java-in-query-with-regex |
| Comments |
| Comment by Rizwan Ishtiaq [ 11/Jun/18 ] | |
|
Hi I am not able to access #FREE-30992 (what is the reason for that?) I am facing some what same problem.
I am passing string because $regex is not allowed with $in operator. I reckon it is not treating it as a regex
| |
| Comment by Jeffrey Yemin [ 04/Dec/13 ] | |
|
Closing this, as it it not an issue with the driver. | |
| Comment by nirav [ 01/Aug/13 ] | |
|
The workaround I am using doesn't seems to be efficient. Regular expression with mulitple "|" seems to performing worse than $in query. I can send explain() if interested. I have also tried $Or query instead of $in, which also seems to be performing worse than $in |