Record the problem due to limitations of the com.mongodb.basicdbobject

Time:2020-2-15

org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDBObject, you can’t add a second ‘createTime’ criteria.
When spring’s mongotemplate query has two restrictions on the same field, improper use will result in an error.
Error case

query.addCriteria(Criteria.where("createTime").gt(startDate()));
query.addCriteria(Criteria.where("createTime").gt(endDate()));

Correct use cases

Criteria criteria = new Criteria();
criteria.andOperator(Criteria.where("createTime").gt(startDate()),  
 Criteria.where("createTime").lt(endDate()));
 
query.addCriteria(criteria);

Recommended Today

Python basics Chinese series tutorial · translation completed

Original: Python basics Python tutorial Protocol: CC by-nc-sa 4.0 Welcome anyone to participate and improve: a person can go very fast, but a group of people can go further. Online reading Apache CN learning resources catalog introduce Seven reasons to learn Python Why Python is great Learn Python introduction Executing Python scripts variable character string […]