whatwhatwhat
whatwhatwhat

Reputation: 2276

Why is my code writing the full path of the doc ID in Firestore?

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

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317712

Use the id property (java getter getId()) of the DocumentReference object doc:

"docID" to doc.id

Upvotes: 1

Related Questions