nutella_eater
nutella_eater

Reputation: 3582

Get id as a field in Firestore

I want to create a small database on firestore. When I made a POST request, I get a response with all the fields, plus some other including name field:

{
    "name": "projects/example-27d5e/databases/(default)/documents/cars/8inm4gXQwzVj5OrBbYoJ",
    "fields": {
        "Field3": {
            "stringValue": "3"
        },
        "Field1": {
            "stringValue": "1"
        },
        "Field2": {
            "stringValue": "2"
        }
    },
    "createTime": "2018-07-29T11:26:52.292609Z",
    "updateTime": "2018-07-29T11:26:52.292609Z"
}

Where 8inm4gXQwzVj5OrBbYoJ is my document id. Is there any way to store this id as a single field?

Upvotes: 2

Views: 2139

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 599011

There is no automated way to store the ID of a document as a field in that document.

In general I'd recommend against doing so, since it's needless duplication of data: whenever you read a document, Firestore returns its ID too. If you're struggling with how to get both the ID and the data while reading, show the code that you've tried, so we can have a look.

Upvotes: 2

Related Questions