`
db.collection("users").document("user").set(map).addOnCompleteListener
`
https://gist.github.com/Lsortudo/52dcce39ffc7c7db358779c87611936b ( Line 70 ) That's my code above... Soo, what i want to do is basically generate User 1, User 2, User 3, but when using 'user' it ends up replacing the previous one (that's something obvius, but idk how to put increment), as would be done to put something in the documentPath to auto-increment or something else that results in creating User1,2, 3
I tried placing an ${counter} and on isSuccessful i would do Counter , but it keeps going back to 1 (u can see on gist)
CodePudding user response:
The private var contador = 1
would be 1 every time you restart the application and so the counter restarts every time. It is not recommended to use sequential IDs in Firetore, checkout Limitations of using sequential IDs in Cloud Firestore for more information.
User's Firebase Auth UID is generally used as the Firestore document ID so it is easier to write security rules as well so try this instead:
db.collection("users").document(Firebase.auth.currentUser.uid).set(map)...