spring data mongo比较两个字段查询

实例

public long countBetweenFields(String userId){
        Criteria criteria = new Criteria() {
            @Override
            public DBObject getCriteriaObject() {
                DBObject obj = new BasicDBObject();
                obj.put("$where", "this.lastUpdateTime > this.lastReadTime");
                return obj;
            }
        };
        Query query = new Query();
        query.addCriteria(Criteria.where("userId").is(userId));
        query.addCriteria(criteria);
        return mongoTemplate.count(query,"forum");
    }

docs

  • how-to-compare-2-fields-in-spring-data-mongodb-using-query-object

  • mongodb-spring-data-comparison-between-fields

  • spring-data-mongodb-compare-two-document-field

你可能感兴趣的:(mongodb)