Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
291 views
in Technique[技术] by (71.8m points)

java - Efficiency of searching using whereArrayContains

I am curious as to the efficiency of searching for documents in a collection using this code. As the number of documents in the collection grows and the number of items in the array grows will this search become very inefficient? Is there a better way of doing this or is there a schema change I can make to the database to better optimize this? Is there somewhere I can find the time complexity of these functions for the firestore documentation maybe?

Query query = db.collection("groups").whereArrayContains("members", userid);


ALTERNATIVE SOLUTION

I originally wanted to try storing the group ids under the user so as to only grab the groups for that current user, but ran into issues and never found a solution for setting a FireStoreRecyclerOptions using multiple ids to query by.

Example:

for(String groupid : list) {
    Query query = db.collection("test-groups").document(groupid);

    FirestoreRecyclerOptions<GroupResponse> response = new FirestoreRecyclerOptions.Builder<GroupResponse>()
            .setQuery(query, GroupResponse.class)
            .build();
}

Is there a way to add multiple queries to the FirestoreRecyclerOptions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...