Reputation: 2276
How can I write the document ID alone instead of the full path? Currently my code is inserting users/pdqr4LyHzbuGle0e8sCr
. I'd rather it insert pdqr4LyHzbuGle0e8sCr
.
var collUsersRef: CollectionReference = db.collection("users")
val doc = collUsersRef.document()
var data: HashMap<String, Any> = hashMapOf(
"docID" to doc
, "email" to email
, "username" to user
, "createDate" to FieldValue.serverTimestamp()
, "modifiedDate" to FieldValue.serverTimestamp()
, "stat" to 1
)
doc.set(data)
Upvotes: 0
Views: 60
Reputation: 317712
Use the id property (java getter getId()
) of the DocumentReference object doc
:
"docID" to doc.id
Upvotes: 1