Quantcast
Channel: Spring Community Forums - NoSQL
Viewing all articles
Browse latest Browse all 128

Spring-Data MongoDb Performing a find with an "OR"

$
0
0
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:

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());
                }
        }

However nothing is being returned in the logItems list.

Appreciate any suggestions.

Viewing all articles
Browse latest Browse all 128

Trending Articles