0

I am trying to import data from a csv file to firestore. I got most of the code down for importing the information over, but I found out that it auto-generates a document ID for every row

Is there a way in python where I can start a document id as 0 and then for every row added, increment the document id by 1

This link shows the python script I used to import data from a csv file: Upload Data to Firebase Cloud

Besides the 10 lines from the link I used, I also added ( not sure this is the right step to take)

n=0 #initialize first doc id
const busnRef = db.collection(u'busnProfile').doc(n)
n+=1 #increment the doc number

1 Answers1

0

Document IDs in Firestore are always strings. You can certainly use a number in string form as an ID, but that's usually not a very good solution to any given problem.

Firestore does not support auto-increment document IDs or field values. This does not scale very well under heavy load. If you want to maintain a count of documents in a collection for the purpose of incrementing some ID or field value, you'll have to maintain a running count in another document, and use that to determine what the next value should be.

If you want to maintain a time-based ordering of documents in a collection, it's probably better to use a timestamp field in each document, and accept the random document ID provided by add().

See also:

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441