admin管理员组

文章数量:1333396

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
Add a ment  | 

1 Answer 1

Reset to default 7

Try this

firetoreDB.collection("collection").doc().id

本文标签: javascriptHow to get firebase firestore generated idStack Overflow