Announcement Announcement Module
Collapse
No announcement yet.
Spring Data MongoDB M4 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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
    Code:
    {'$or' :[{'date': null},{'date':{'$gt': (somedatevalue) }}]
    The reason I ask for a NON-Criteria method is because when using Criteria I get exceptions.

    Specifically:
    org.springframework.data.mongodb.core.query.Criter ia or() Method requests a List<Query> as its only parameter.
    However once passing that Criteria through MongoTemplate it runs it through the class org.springframework.data.mongodb.core.QueryMapper and on line 96 it does a cast from Object to BasicBSONList.
    Code:
    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:

    Code:
    	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.

    Comment


    • #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:
      https://jira.springsource.org/browse/DATADOC-300

      Comment

      Working...
      X