Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How do add document in a subcollection of a firebase database

Issue

I am having an issue with creating a reference to other documents in my Firebase/Firestore database during document creation query. I have tried using string concatenation but it only results in a string type field instead of a reference. I have submitted a feature request for specifying the type of data to load in Firestore. As a workaround, I am sending a map object with the reference path and ID.

Resolution

The problem was how to create a reference to another document inside a Firestore database using Appsmith. The user had designed a database with sub-collections and references to other documents. However, when they tried to create the reference during the creation query of the document, the type of field "ingredient" was a string, and not a reference to the document.

To solve this issue, the user found a workaround: they sent a map object to Firestore with the reference object containing a path and ID to the desired document, along with the other fields and values. The map object looked like this:

{
"ref_object": {
"path" : "collection/OBJECTID",
"id" : "collection/OBJECTID"
},
"field": "value"
}

Although it was not an ideal solution, it worked for the user. They also submitted a feature request to Appsmith to allow the user to select the type of data they want to send to Firestore, which could help solve this issue in the future.