question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding a subcollection

See original GitHub issue

Do you want to request a feature or report a bug?
bug

Is it posible to add a subcollection to firestore using redux-firestore? What is the current behavior? when I add a sub document I like the code below:

withHandlers({ startNewProcess: props => () => props.firestore.add(Region/${region}/office/${id}, { name:props.name}) }) I have also tried props.firestore.add({collection:“Region”,doc:region,subcollections[collection:“office”],doc:id}, { name:props.name}) I get the error below:

Cannot read property ‘apply’ of undefined at wrapInDispatch (actions.js:57) at Object.add (firestore.js:52) at Object.add (actions.js:92) at NewProcessForm.jsx:140 at Recompose.esm.js:183 at HTMLUnknownElement.callCallback (react-dom.development.js:100) at Object.invokeGuardedCallbackDev (react-dom.development.js:138) at Object.invokeGuardedCallback (react-dom.development.js:187) at Object.invokeGuardedCallbackAndCatchFirstError (react-dom.development.js:201) at executeDispatch (react-dom.development.js:461) at executeDispatchesInOrder (react-dom.development.js:483) at executeDispatchesAndRelease (react-dom.development.js:581) at executeDispatchesAndReleaseTopLevel (react-dom.development.js:592) at forEachAccumulated (react-dom.development.js:562) at runEventsInBatch (react-dom.development.js:723) at runExtractedEventsInBatch (react-dom.development.js:732) at handleTopLevel (react-dom.development.js:4476) at batchedUpdates$1 (react-dom.development.js:16659) at batchedUpdates (react-dom.development.js:2131) at dispatchEvent (react-dom.development.js:4555) at interactiveUpdates$1 (react-dom.development.js:16714) at interactiveUpdates (react-dom.development.js:2150) at dispatchInteractiveEvent (react-dom.development.js:4532) wrapInDispatch @ actions.js:57 add @ firestore.js:52 (anonymous) @ actions.js:92 (anonymous) @ NewProcessForm.jsx:140 (anonymous) @ Recompose.esm.js:183 callCallback @ react-dom.development.js:100 invokeGuardedCallbackDev @ react-dom.development.js:138 invokeGuardedCallback @ react-dom.development.js:187 invokeGuardedCallbackAndCatchFirstError @ react-dom.development.js:201 executeDispatch @ react-dom.development.js:461 executeDispatchesInOrder @ react-dom.development.js:483 executeDispatchesAndRelease @ react-dom.development.js:581 executeDispatchesAndReleaseTopLevel @ react-dom.development.js:592 forEachAccumulated @ react-dom.development.js:562 runEventsInBatch @ react-dom.development.js:723 runExtractedEventsInBatch @ react-dom.development.js:732 handleTopLevel @ react-dom.development.js:4476 batchedUpdates$1 @ react-dom.development.js:16659 batchedUpdates @ react-dom.development.js:2131 dispatchEvent @ react-dom.development.js:4555 interactiveUpdates$1 @ react-dom.development.js:16714 interactiveUpdates @ react-dom.development.js:2150 dispatchInteractiveEvent @ react-dom.development.js:4532

What is the expected behavior? I expect that the data will stored in firestore under the subcollection in the case “office” with the id provided.

Which versions of dependencies, and which browser are affected by this issue? Did this work in previous versions or setups? I am using version 2.

Steps to reproduce and if possible a minimal demo of the problem via codesandbox or similar.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
tebogoscommented, Jul 20, 2018
const docRefConfig = { collection:"Region", doc: "someRegion", subcollections: [{ collection:"office", doc: `${id}` }] }
 props.firestore.set(docRefConfig, { name:props.name })

I think I got the Markdown correct now. Thanks for the tip!

0reactions
tebogoscommented, Jul 20, 2018

When specifiying your own document id at the subcollection level, you can no longer call add since that is for adding documents. If you are trying to update a document at that level you will want to call update like so:

I got it working by using set like so:

const docRefConfig = { collection:"Region", doc: "someRegion", subcollections: [{ collection:"office", doc: `${id}` }] } props.firestore.set(docRefConfig, { name:props.name }) Thank you very much for you prompt help and tips! Regards, Tebogo.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to add subcollection to a document in Firebase Cloud ...
There is no separate method to add sub-collection into the document. You can just call the collection ...
Read more >
Create a Firestore subcollection reference - Google Cloud
Stay organized with collections Save and categorize content based on your preferences.
Read more >
Adding a subcollection in the Web Designer
Adding a subcollection in the Web Designer · To create just the table and IDO, click No. · To create a form to...
Read more >
Cloud Firestore Data model - Firebase
The best way to store messages in this scenario is by using subcollections. A subcollection is a collection associated with a specific document....
Read more >
How To Add Sub Collections In Shopify? - BSS Commerce
Why do you need to add sub-collections to your Shopify store? · Use link lists to create a collection tree before you start...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found