Announcement Announcement Module
No announcement yet.
Spring Data MongoDB M4 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data MongoDB M4

    Is there another method to do an OR query other than using criteria?

    Specifically i would like to query
    {'$or' :[{'date': null},{'date':{'$gt': (somedatevalue) }}]
    The reason I ask for a NON-Criteria method is because when using Criteria I get exceptions.

    Specifically: ia or() Method requests a List<Query> as its only parameter.
    However once passing that Criteria through MongoTemplate it runs it through the class and on line 96 it does a cast from Object to BasicBSONList.
    BasicBSONList conditions = (BasicBSONList) value;
    But since the passed in value is a List<Query> it throws a cast exception.

  • #2
    You can always construct your $or query using the OrQuery class:

    	Query q1 = new Query(Criteria.where("date").is(null));
    	Query q2 = new Query(Criteria.where("date").gt(new Date()));
    	Query q = new OrQuery(q1, q2);
    I'll take a look to see why the Criteria.or() leads to a serialization error.


    • #3
      That Criteria.or() method is broken. We are considering some options to make this easier to use as well as work without exceptions.

      I'm thinking of making the method take one or more Criteria as parameters instead of List<Query>, but we are still working out the details.

      You can keep track of the progress here: