I'm trying to create a dynamic mongodb query using spring criteria. My
query is : Criteria.where(key1).is(value1 .and(key2).is(value2)
If I use it the query works but if I try:
new
Criteria().andOperator(Criteria.where(key1).is(value1),Criteria.where(key2) .is(value2))
It doesn't works. I would want to use the second solutions because the
number of keys and values aren't fixed.
Can someone tell me what's the difference beetween these solutions or where
is the error?
I'll try to create manually the query but it doesn't work:
BasicDBList andList = new BasicDBList();
andList.add(new BasicDBObject(key1,value1));
andList.add(new BasicDBObject(key2,value2));
BasicDBObject queryObject = new BasicDBObject("$and", andList);
but
mongoTemplate.getCollection(collectionName).find(queryObject);
is empty!
Can someone hel me to find errors?
Thanks too much.