I want to create a document in firestore with an unique id and a name after the unique id. For this, I want to create the same kind of the firebase firestore unique ids.
- How can I create an unique ID with the kind of a auto generated firestore id?
- Is there a function in the Firebase Admin SDK?
UPDATE:
As Frank van Puffelen mentied in the comments, the AutoId is the right choice for me!
Here is the function I use on server-side with node.js:
function generateUniqueFirestoreId(){
// Alphanumeric characters
const chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let autoId = '';
for (let i = 0; i < 20; i++) {
autoId += chars.charAt(Math.floor(Math.random() * chars.length));
}
return autoId;
}