-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
feat(query): both doc and subcollection within a single query #52
Comments
Hm, maybe I missunderstood the docs: thought that this would get me the cities/SF + cities/sf/zipcodes? Is this the correct behavior? |
@compojoom That is correct behavior currently, but I have noticed this means repeating myself in a few places. What are your thoughts on the potential of an option on the query to get both the document and the subcollection? Under the hood it would be two queries, but it might mean much less repeating ourselves. Maybe something like: {
collection: 'cities',
doc: 'SF',
includeDoc: true, // <- this option, but maybe a different name?
subcollections: [{ collection: 'zipcodes' }]
} |
Well, actually - once you know that you can't do it in one go it's a no-brainer. Maybe we should change the docs and mention this behavior? |
Hi I have slightly different problem. I figure it out that i need to do multiple queries to get document with his subcollections. So I did something like this:
And it works correctly for
But for
The workaround is to use
Is this a bug or intended behavior? |
@Sgiath What you are mentioning should no longer be an issue in the most recent versions. There was an issue in the ordered reducer which was fixed. Can you confirm? |
hi guys i wanna ask,,,,can we change this option to a local state? Thx for any help
|
@JoshSum - before firestoreConnect is called - your redux selector is being executed. So if in the selector you return {docId: myDocId} and you change your firestore connect to accept props as first argument, then you can access prop.docId
|
@compojoom I have many documentId on each subcollection.... how to check if exist, then firestoreconnect, if not exist dont do firestoreconnect, but i have default connect on top of this....
|
|
@compojoom and @prescottprue ....Please how can i automatically query a collection and its subcollection without knowing the doc id of each document? I have a collection and subcollection with different documents but i want to return each collection with its subcollection in single query. How do i go about it in react-redux-firestore?? e.g supaPosts is a collection with supaPostLikes as subcollection, so the idea now is to fetch each doc from supaPosts and use the doc id each of supaPosts to query its subcollection and return if the currentUserId is present in each supaPosts subcollection supaPostLikes... Here is the nature of my database model now am trying something like this....
Now how do i get the doc id called something of each supaPosts document and use it to query its subcollection supaPostsLikes and return if likerId is equal to currentUserId?? Or it is not possible to do so |
@SUPERTEMPO That would be creating one query then another query, so first the query for all of the posts, then a query for each post to get the likes. It would probably be best to do this using the multiple levels of your components as a way to structure your listeners: Structure
Listeners firestoreConnect((props) => {
return [
{ collection: 'supaPosts', orderBy: ['supaPostTime', 'desc'], limit:10 }
]
}) SupaPost firestoreConnect((props) => {
return [
{
collection: 'supaPosts',
doc: props.postId,
subcollections: [
{
collection: 'supaPostLikes',
where: [
['likerId', '==', **currentUserId**]
]
}
]
}
]
})) |
@prescottprue i did exactly as you have written but rather this query
is picking just the first props.postId and returning multiple times for the number of limit i have which is 10 and even overwriting the supaPosts state. when i tried to use storeAs postLiked, it is returning but still multiple data for only the first props.postId. Dunno what to do.... dunno if there is any way round .......thanks |
@SUPERTEMPO you should try making a storeAs that contains that id such as storeAs: `${props.postId}-postLikes` |
@prescottprue thanks man.... You are great..... it worked perfectly.....thanks so much.... You really saved me, keep doing the good work..... |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
I'm trying to request a collection and a subcollection:
{
collection: 'companies', doc: company,
subcollections: [{ collection: 'users' }]
}
What is the expected behavior?
the expected behavior is to receive the doc + a subcollection
Instead the subcollection overrides all properties of the doc. So one ends only with the subcollection data.
The text was updated successfully, but these errors were encountered: