PDA

View Full Version : whick criterion use $ne operation? and i have problem when using in,nin



afriday
Apr 25th, 2011, 11:26 PM
i want to do $ne operation, but i have not found a criteria match it.
and the in ,nin seems working incorrectly, i insert 4 persons


Person p1 = new Person("Bob", 33);
mongoTemplate.insert(p1);
Person p2 = new Person("Mary", 25);
mongoTemplate.insert(p2);
Person p3 = new Person("Chris", 68);
mongoTemplate.insert(p3);
Person p4 = new Person("Janet", 29);
mongoTemplate.insert(p4);

when i use in operation, it print none


List l = Arrays.asList(25);
List<Person> ps = mongoTemplate.find(new Query(where("age").in(l)), Person.class);
for(Person s : ps) {
System.out.println(s);
}

and when i use nin operation, it print the all persons

thank you for help!

afriday
Apr 26th, 2011, 01:10 AM
oh, get it , in(),nin() need an array argument, where("age").in(l.toArray()) is working correctly

Mark Pollack
Apr 26th, 2011, 11:46 AM
Hi,

I've created two issues to fix the usage issues you mention. DATADOC-106 (https://jira.springsource.org/browse/DATADOC-106) is about adding some operations that aren't on the Criteria class, such as $ne. DATADOC-107 (https://jira.springsource.org/browse/DATADOC-107) is to let you pass in collections instead of arrays so you don't have to do the l.toArray() yourself.

Mark