react-redux-firebase icon indicating copy to clipboard operation
react-redux-firebase copied to clipboard

How to populate from firestore within a subcollection ?

Open GautierT opened this issue 5 years ago • 5 comments

Hi, I have a subcollection of ingredients containing data and a ref to the main ingredients collection. image

I want to populate data on my subcollection with the data from the main ingredients collection.

I thought about doing something like this :

  useFirestoreConnect([
    {
      collection: "users_lists",
      doc: listId,
      subcollections: [
        {
          collection: "ingredients",
          populates: [{ child: "ref", root: "ingredients" }],
        },
      ],
      storeAs: "my_ingredients",
    },
  ])

but i still the firestore object in my redux store : image

I can't find in the doc how to do that.

Thanks for the help !

GautierT avatar Apr 27 '20 13:04 GautierT

Hmm interesting use case - I believe the populate parameters should live on the top level. Also how are you selecting data from state?

prescottprue avatar Apr 27 '20 20:04 prescottprue

I was expecting data to be populated in the redux store. To have a clean database with all needed data populated on the redux store and be able to pick what i need in it. I have to use connect ?

GautierT avatar Apr 28 '20 13:04 GautierT

@GautierT Yes - populate attaches listeners for all needed data, which then goes into the redux store UNPOPULATED, this is so that you can populate in some places and not others if needed based on how you connect to state. To pull populated data out of state, use the populate util which grabs the data and combines it based on populate settings

prescottprue avatar May 01 '20 22:05 prescottprue

@GautierT So is this good to close with that understanding? We might also want to clarify further in the populate docs

prescottprue avatar May 31 '20 21:05 prescottprue

Hi. I'm unable to populate data between two collections if they are both at the top level in Firestore, but I'm struggling to populate data between two collections if they are in subcollections (2nd level) using the same populates parameter.

Are there instructions on populating data in subcollections?

jyw3084 avatar Oct 27 '22 01:10 jyw3084