簡體   English   中英

Spring Data Mongo:通過數組交集查找

[英]Spring Data Mongo: Find by array intersection

我使用Spring Data DSL以下列方式查詢MongoDB:

Page<Member> findByCommunitiesCodeContaining(String code, Pageable pageable);

它返回具有給定代碼的社區的所有成員。

問題:我需要傳遞一組社區代碼,並從列出的代碼中返回參與至少一個社區的成員(社區的交集不為空)。

我瀏覽了Spring Data Mongo文檔,但找不到支持這種情況的DSL。

問題:如何查詢具有集合交集的記錄?

更多細節。 以下是我的結構在Java方面的外觀。

@Document
public class Member {
    @Id
    private String id;
    private List<Community> communities;
}

社區:

public class Community {
    private String region;
    private String code;
}

一種選擇可能是使用正則表達式

Page<Member> findByCommunitiesCodeRegex(String code, Pageable pageable);

代碼應該是一個正則表達式:

String code = (code1|code2|code3|....)

希望它有所幫助,我沒有嘗試過,但值得嘗試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM