usama abdul razzaq
usama abdul razzaq

Reputation: 111

Manually generate Firebase firestore document ID

i want to generate Document ID manually for firestore, is this possible. The scenario will be a Record of cars. Example

Car: {
  chasisNumber : "Ab129011", <-- // always unique
  modelNumber : "2020MBW",
  year : "2020",
  name : "BMW",
}

In this scenario i want to create chasisNumber as document ID because it is unique, how can i do this. I want this scenario in React-hooks

Upvotes: 1

Views: 692

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600126

As the first example in the Firestore documentation on adding data shows, you can pass any value to the doc call to use that as the document ID.

So:

// Add a new document in collection "cities"
db.collection("cities").doc("Ab129011").set({
  chasisNumber : "Ab129011",
  modelNumber : "2020MBW",
  year : "2020",
  name : "BMW",
})

Upvotes: 1

Related Questions