Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Query by subcollection #1009

Closed
sondresorbye opened this issue Jul 14, 2018 · 7 comments
Closed

FR: Query by subcollection #1009

sondresorbye opened this issue Jul 14, 2018 · 7 comments

Comments

@sondresorbye
Copy link

sondresorbye commented Jul 14, 2018

I want to get all teams where the user is a member of. Currently, I am querying by a object with uid as key.

The teams can potentially have thousands of members and the user can be member of many teams. Therefore, this approach is not scalable. A better approach would be to query be a subcollection with all users.

I also could make another collection to make a relationship between the users and teams (like SQL databases). The problem with this is that a have to make another request to Firestone.

Is it a scalable solution to this?

@codediodeio
Copy link
Contributor

In Cloud Datastore it's possible to get up to 1,000 entities with an array of keys.

datastore.get( [...keys] )

Is something similar on the roadmap in Firestore? I think this could solve many of the relational challenges like the one referenced above.

@Thaina
Copy link

Thaina commented Jul 26, 2018

user can be member of many teams

Don't think subcollection query would satisfied this case

Instead I think you need

//team doc
{
    "members" : {
         "userID1" : true,
         "userID2" : true,
         "userID3" : true,
         "userID4" : true,
    }
}
var teamQuery = db.Collection("teams").WhereEqualTo("members.{userID}",true);

@sondresorbye
Copy link
Author

@Thaina, this is the solution I am currently using. However, this approach is not very scalable. A team couød potentially have thousands of members.

@mohshraim
Copy link

i think same FR already exist
#572

@Thaina
Copy link

Thaina commented Jul 31, 2018

@sondresorbye0111 Then you need the opposite, storing teamID in user doc. Given that the more possible side of relation would be the main to store the less one

And if you need true scalable of both side. Maybe you need another collection, a relationship collection. Which is storing very small document, only

docid : "teamID:userID"
{
    "team" : "{teamID}",
    "user" : "{userID}",
}

And so you could query both way

@sondresorbye
Copy link
Author

@Thaina, this is a solution, but it requires two roundtrips to the database. Therefore, I think it would actually be slower than downloading some extra other users IDs.

@wilhuff
Copy link
Contributor

wilhuff commented Sep 12, 2018

Thanks for your interest! This is a duplicate of #572.

As we said there, this is definitely on the road map. Right now we're working on stabilizing what we have for GA so this isn't imminent, but this is very high on our list of priorities, don't worry :-).

@wilhuff wilhuff closed this as completed Sep 12, 2018
@firebase firebase locked and limited conversation to collaborators Oct 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants