Home > Mobile >  Firestore DB: Create collection inside a document using REST API
Firestore DB: Create collection inside a document using REST API

Time:12-07

I'm creating an app that requires me to create a new collection inside existing document. I know it can be done on the firestore DB with a few clicks.

I want to do the same with a REST API

Something like this

Is there any way to implement this using a REST API

Thanks!

I tried looking for docs in the official website but couldn't find anything.

CodePudding user response:

To create a subcollection using the firestore REST API, use the url below.

NB// Replace all variables that start with YOUR

https://firestore.googleapis.com/v1/projects/<YOUR_PROJECT_ID>/databases/(default)/documents/<YOUR_COLLECTION_NAME>/<YOUR_DOCUMENT_ID>/<YOUR_SUBCOLLECTION_NAME>?documentId=<YOUR_RANDOM_ID>

Also, use the json example below for the request body because this is a POST request.

{
  "fields":{
    "name":{
      "stringValue":"This is a new document in a subcollection"
    }
  }
}
  • Related