I'm using Java Mongo DB driver.
Im doing some OR and AND operation to query the collection.
QueryObj = new BasicDBObject("key1",Pattern.compile("v",Pattern.CASE_INSENSITIVE));
QueryList.add(QueryObj);
DBObject OrQuery = new BasicDBObject("$or", QueryList);
DBCursor cursor = MyCollection.find(OrQuery);
my Sample collection have 4 rows(JSON format might be wrong)
{
"key1": ["val1","val3"]
},
{
"key1": ["val2","val3"]
},
{
"key1": ["val3"]
},
{
"key1": ["val1","val2"]
}
If i search for "val2"
QueryObj = new BasicDBObject("key1",Pattern.compile("val2",Pattern.CASE_INSENSITIVE));
i'm getting expected output 2nd and 4th row
{
"key1": ["val2","val3"]
},
{
"key1": ["val1","val2"]
}
if i search just "v"
QueryObj = new BasicDBObject("key1",Pattern.compile("v",Pattern.CASE_INSENSITIVE));
i should get null set, but getting all the 4 rows, though the array have a character "v".
i need to search the whole word.