spring data mongo比較兩個欄位查詢

weixin_33763244發表於2016-09-27

例項

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

相關文章