简体   繁体   中英

querying for records with date between two dates in mongo

I am having a problem where I am trying to find records with a particular username and where the start date is between a start and end date. I have searched around and below is the seemingly agreed upon answer for how to do this. Unfortunately when I use it I still get the same error:

Due to limitations of the com.mongodb.BasicDBObject , you can't add a second 'start' expression specified

The query I am attempting to use is:

Query query = new Query(
                        Criteria.where("username").is(username)
                            .andOperator(
                                Criteria.where("start").lt(DateUtils.ceiling(date)),
                                Criteria.where("start").gte(DateUtils.floor(date)) 
                             )
                        );

I am using spring-data-mongoldb 1.8.4.RELEASE

So this does in fact work properly. I just spent the last few hours ripping my code apart and rewriting it... Comparing with version in git shows no differences except now it works.

Just wanted to post this answer for anyone who comes looking. I really have no explanation as I was cleaning the project between runs, perhaps some copy of the old class was being held by the app server.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM