Issue
I want to add to the "receipts" collection a document with a unique "id: and for this document the data:" id "," from "," value "and" image ". Firebase !!important !!code in Fragment
Solution
If you need to add a document to a specific collection with a unique ID, then you should use the DocumentReference#set() method which:
Writes to the document referred to by this DocumentReference.
In code, it should look like this:
val db = FirebaseFirestore.getInstance()
val receiptsRef = db.collection("receipts")
val docId = receiptsRef.document().id
val receipt = mapOf(
"id" to docId,
"from" to "Name",
"value" to "The value of the receipt",
"image" to "URL of the image"
)
receiptsRef.document(docId).set(receipt)
You can also use addOnCompleteListener(OnCompleteListener listener), to see if something goes wrong.
Answered By - Alex Mamo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.