I have two firebase collections one is builderData and another is adviserData, both contains a filed named ‘Property Id’. I want to update the value of a property in both the collections where the Property Id’s are equal in both collections.
On Pressing of this button I want to update the property based on the Property Id in both the collections adviserData and builderData.
ElevatedButton.icon(
onPressed: () {
CollectionReference buildercollRef =
FirebaseFirestore.instance.collection('builderData');
CollectionReference adviserdocRef =
FirebaseFirestore.instance.collection('adviserData');
buildercollRef.doc(widget.propertyId).update({
'Property Title': propertyTitleController.text,
'Property Address': propertyAddressController.text,
'Property Cover': propertyCoverController.text,
'Property Description': propertyDescriptionController.text,
'Google Maps Link': propertyLocationController.text,
'Property Status': propertyStatusController.text,
'Price Sqft': pricePerSqftController.text,
'Posssesion Date': possessionDateController.text,
'Max Sqft': maxAreaController.text,
'Min Sqft': minAreaController.text,
'Rera Id': rearaIdController.text,
'Total Floors': totalFloorsController.text,
'Total Units': totalUnitsController.text,
'One Bhk': oneBhkConfigController.text,
'Two Bhk': twoBhkConfigController.text,
'Three Bhk': threeBhkConfigController.text,
'Four Bhk': fourBhkConfigController.text,
'Five Plus Bhk': fivePlusBhkConfigController.text,
'Launch Date': launchDateController.text,
'Total Project Area': totalProjectAreaController.text,
})
2
Answers
It sounds like you’ll want to use a query on each collection to find the documents matching the property ID. For example, for the
builderData
that could look like this:And then you’ll need to do the same for the other collection where you want to update a document.
Here we can first check for the documents and get the documents which have the property Id equals to the property Id passed, then we will get the document snapshot of all those documents later we can get the document id of the first document and do the update operation. Hope below code will help you.