I need some assistance as to how to find all entries in the collection which have one of two values.
I have implemented the LogItem project from the http://pragmaticintegrator.wordpress...mongodb-setup/
I am trying to get a list from the collection where the message is "just some text1" or "just some text2".
Here is my code:
However nothing is being returned in the logItems list.
Appreciate any suggestions.
I have implemented the LogItem project from the http://pragmaticintegrator.wordpress...mongodb-setup/
I am trying to get a list from the collection where the message is "just some text1" or "just some text2".
Here is my code:
Code:
public void executeOrQuery() {
MongoOperations mongoOps = mongoTemplate;
Criteria criteria1 = Criteria.where("message").is("just some text1");
Criteria criteria2 = Criteria.where("message").is("just some text2");
Query messageOrQuery = new Query(criteria1);
Query queries = new Query(criteria2);
messageOrQuery.or(queries );
messageOrQuery.fields().include("_id");
messageOrQuery.fields().include("message");
List<LogItem> logItems = mongoOps.find(messageOrQuery, LogItem.class, "logItem");
for (int index = 0; index < logItems.size(); index++){
System.out.println(logItems.get(index).getId() + ", " + logItems.get(index).getMessage());
}
}
Appreciate any suggestions.