To add data on firestore, we should work on some thing
- first we should get the Instance of Firestore to connect our data to firestore.
private var db:FirebaseFirestore = FirebaseFirestore.getInstance()
2. Our variable is db , whenever we want to get reference of our firestore then use this variable db.
val add = HashMap<String,Any>()
3. Than add HashMap<key, value> to add our data.
add["firstName"] = "your first name"
add["lastName"] = "your last name"
add["email"] = "your email id"
add["password"] = "your hide password"
4. In this add[“your key”] = “your value”
db.collection("users")
.add(add)
.addOnSuccessListener {
Toast.makeText(this,"Data added ",Toast.LENGTH_LONG).show()
}
.addOnFailureListener {
Toast.makeText(this," Data not added ",Toast.LENGTH_LONG).show()
}
5. In the collection(“ your collection name”) ,than add(your data variable name),
6. After than you can see your data in your Firebase Firestore
Hope it will work
Thanks