[JAVA-1114] Regular Expression on IPAddress format like does not work as expected Created: 17/Feb/14  Updated: 16/Jul/15  Resolved: 10/Mar/14

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: 2.4
Fix Version/s: None

Type: Bug Priority: Critical - P2
Reporter: Sridhar Assignee: Ross Lawley
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

2.4 & Above


Backwards Compatibility: Fully Compatible

 Description   

I am using Mongo 2.4.9, and I use simple search for my application for IPAddress search.

I give search some thing like: "192.168.1.1*" , but it returns even with IP Address starting from 192.168.2* and 192.168.4* which are in my db. It has to respond only with 192.168.1.1*. details of execution is below and it would be really great help if I know which version of latest MONGO has a fix for this kind of issue if at all be raised by some one already and have been fixed. If not fixed this is the major bug for my release this week.

Query: { "$and" : [ { "ipAddress" : { "$regex" : "192.168.1.*"}}]}, Fields: null, Sort: null
192.168.1.102
192.168.1.114
192.168.1.117
192.168.1.123
192.168.1.130
192.168.1.140
192.168.1.151
192.168.1.155
192.168.1.158
192.168.1.182
192.168.1.220
192.168.1.221
192.168.1.223
192.168.1.224
192.168.1.225
192.168.1.226
192.168.1.227
192.168.1.228
192.168.1.229
192.168.1.230
192.168.1.231
192.168.1.232
192.168.1.233
192.168.1.234
192.168.1.235
192.168.1.236
192.168.1.237
192.168.1.238
192.168.1.239
192.168.1.240
192.168.1.241
192.168.1.242
192.168.1.243
192.168.1.244
192.168.1.245
192.168.1.246
192.168.1.247
192.168.1.248
192.168.1.250
192.168.1.251
192.168.1.252
192.168.1.253
192.168.1.254
192.168.1.255
192.168.4.163
192.168.4.63



 Comments   
Comment by Ross Lawley [ 10/Mar/14 ]

Hi there,

This Jira project is intended only for issues with the MongoDB Java driver. The question you are asking here is more appropriate for our users group, which you can find here: https://groups.google.com/forum/#!forum/mongodb-user.

I did notice that your query didn't match the listed example eg: matching all documents 192.168.1.1* the example given is checking 192.168.1*.

As you are working with regular expressions and you want to search against a string that contains dots you should escape them as in regular expressions dots match almost any character. eg:

db.myDatabase.find( { "ipAddress" : { "$regex" : "192\.168\.1\.1(.*)"}})

Thanks,

Ross

Generated at Thu Feb 08 08:53:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.