when I debug query of criteria $in, i find a bug in the jar: [spring-data-mongodb-1.2.0.RELEASE-sources.jar
] file path: org.springframework.data.mongodb.core.query.Criter ia
the expect result is :{ "age" : { "$in" : [ 11 , 12 , 13]}}, but in fact the query is :{ "age" : { "$in" : [[ 11 , 12 , 13]]}}
my paramter is a list,
the result is :
2013-09-06 14:44:14,921-[HL] DEBUG main org.springframework.data.mongodb.core.MongoTemplat e - find using query: { "age" : { "$in" : [[ 11 , 12 , 13]]}} fields: null for class: class domain.model.Customer in collection: customer
but expected value is:
So I copy the "Criteria.java" in my project ,note the two mothod, add a new method,for example:
and it work!!!
] file path: org.springframework.data.mongodb.core.query.Criter ia
the expect result is :{ "age" : { "$in" : [ 11 , 12 , 13]}}, but in fact the query is :{ "age" : { "$in" : [[ 11 , 12 , 13]]}}
my paramter is a list,
Code:
1.
List ageList = new ArrayList();
ageList.add(11);
ageList.add(12);
ageList.add(13);
2.
criteria.and(prop).in(ageList);
Code:
/**
* Creates a criterion using the $in operator
*
* @param o the values to match against
* @return
*/
public Criteria in(Object... o) {
if (o.length > 1 && o[1] instanceof Collection) {
throw new InvalidMongoDbApiUsageException("You can only pass in one argument of type "
+ o[1].getClass().getName());
}
criteria.put("$in", Arrays.asList(o));
return this;
}
/**
* Creates a criterion using the $in operator
*
* @param c the collection containing the values to match against
* @return
*/
public Criteria in(Collection<?> c) {
criteria.put("$in", c);
return this;
}
the result is :
2013-09-06 14:44:14,921-[HL] DEBUG main org.springframework.data.mongodb.core.MongoTemplat e - find using query: { "age" : { "$in" : [[ 11 , 12 , 13]]}} fields: null for class: class domain.model.Customer in collection: customer
but expected value is:
Code:
2013-09-06 14:44:14,921-[HL] DEBUG main org.springframework.data.mongodb.core.MongoTemplate - find using query: { "age" : { "$in" : [ 11 , 12 , 13]}}fields: null for class: class domain.model.Customer in collection: customer
So I copy the "Criteria.java" in my project ,note the two mothod, add a new method,for example:
Code:
/**
* Creates a criterion using the $in operator
*
* @param o the values to match against
* @return
*/
// public Criteria in(Object... o) {
// if (o.length > 1 && o[1] instanceof Collection) {
// throw new InvalidMongoDbApiUsageException("You can only pass in one argument of type "
// + o[1].getClass().getName());
// }
// criteria.put("$in", Arrays.asList(o));
// return this;
// }
/**
* Creates a criterion using the $in operator
*
* @param c the collection containing the values to match against
* @return
*/
// public Criteria in(Collection<?> c) {
// criteria.put("$in", c);
// return this;
// }
public Criteria in(Object o) {
criteria.put("$in", o);
return this;
}
and it work!!!