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

相關文章
相關標籤/搜索