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

    原文作者:codecraft
    原文地址: https://segmentfault.com/a/1190000007018484
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞