標籤:blog io for sp cti log on c ad
@DBref文檔關聯,在按該類型查詢的時候,在欄位名後加上關聯表的欄位名即可,如:
Criteria.where("bloggroup.$id"),
$id代表關聯表的oid欄位。
or和and聯集查詢
比如查詢 (A = 1 and b = 2 )or (A = 3 and b =4),or的數量不確定,
那麼採用定義一個Criteria數組,將條件組記入數組中,然後將數組指定給orCriteria方法。
@Override
public List<Blog> find(List<GroupAttention> groupattentions) {
Query query = new Query();
Criteria criteria = new Criteria();
Criteria[] criterialist = new Criteria[groupattentions.size()];
for(int i=0;i<groupattentions.size();i++){
Criteria criteriaand = new Criteria();
criteriaand.andOperator(Criteria.where("bloggroup.$id").is(new ObjectId(groupattentions.get(i).getGroupid())).and("bloglevel").gte(groupattentions.get(i).getGrouplevel()));
criterialist[i] = criteriaand;
}
criteria.orOperator(criterialist);
query.addCriteria(criteria);
return mongoTemplateDataBase.find(query, Blog.class);
}
Spring DATA MongoDB @DBref查詢,or和and聯集查詢