Spring Data MongoDB Date Between

后端 未结 9 1950
臣服心动
臣服心动 2020-12-23 17:47

I use spring data mongodb.

I want the records between two dates. The following MongoDB Query works:

db.posts.find({startDate: {$gte: start, $lt: end}         


        
相关标签:
9条回答
  • 2020-12-23 18:33
    if (metaData.getToValue() == null){
    dynamicCriteria = Criteria.where("metaData.key").is(metaData.getKey()).andOperator(Criteria.where("metaData.value").is(metaData.getFromValue()));
    }else {
    dynamicCriteria = Criteria.where("metaData.key").is(metaData.getKey()).orOperator(Criteria.where("metaData.value").gte(metaData.getFromValue()).lt(metaData.getToValue()));
    }
    
    0 讨论(0)
  • 2020-12-23 18:34

    It works, he is some sample code:

    Criteria criteria = Criteria.where("pt").gte(startDate)
           .andOperator(Criteria.where("pt").lt(endDate));
    
    0 讨论(0)
  • 2020-12-23 18:35

    Reference here

    Query query = new Query(
      Criteria.where("ip").is(ip)
      .andOperator(
        Criteria.where("createdDate").lt(endDate),
        Criteria.where("createdDate").gte(startDate)
      )
    );
    
    0 讨论(0)
提交回复
热议问题