Reputation:
I Want to preform and update query using Firestore. i know how to work with it but not completely.
I have a flatlist which presenting data and an a text with touchable opacity onPress that will create a new Firestore collection and set the flatList to Firestore.
What is my goal? : 1.I want to check if there is any data in the collection, if there is a data, i want to update it without overwrite the previous data depending on the current user ID.
My current query code:
const handleFBAll = () => {
// const businessUser = snapshot.docs[0].data();
const businessIde = currentBusinessUid;
console.log("ID : ", businessIde);
firebase.firestore().collection("users").doc(businessIde).collection("pending-sales").doc(currentUser.uid).set({servicesMaxMin})
}
now i want to update the doc of the currentUser with additional data if there is one
Suggetions?
Upvotes: 1
Views: 1064
Reputation: 1548
You can use merge
prop with set
and that should allow you to simplify the code a little like so:
db.collection('dogs').doc('my-id').set({
"owner": "james"
},{merge:true})
this will add owner
prop if it doesn't exist or will overwrite it.
Upvotes: 1