i had an issue where i would like to generate the unique id without sending any data. Below is my code of getting the id, but i would like to get it before i could send the actual data to the database
var getUniqueId = firetoreDB.collection("collction").add({
data: "data"
}).then(function (doc) {
console.log(doc.id);
}).catch(function (error) {
console.log(error);
});
The above code gets me the id but i wanted to get it without out sending a test data to the database
i had an issue where i would like to generate the unique id without sending any data. Below is my code of getting the id, but i would like to get it before i could send the actual data to the database
var getUniqueId = firetoreDB.collection("collction").add({
data: "data"
}).then(function (doc) {
console.log(doc.id);
}).catch(function (error) {
console.log(error);
});
The above code gets me the id but i wanted to get it without out sending a test data to the database
Share Improve this question asked Mar 24, 2018 at 8:50 Jama MohamedJama Mohamed 3,4154 gold badges31 silver badges50 bronze badges 1-
1
You can use
firetoreDB.collection("collection").doc()
to to create a document with an auto-generated ID – Alexander Commented Mar 24, 2018 at 9:00
1 Answer
Reset to default 7Try this
firetoreDB.collection("collection").doc().id