I have tried to store a Map of data with set method, but everytime it overwrites the data in firebase. With update method setting that same Map of data works, it does not overwrite, but creates a new array and stores it.
I want to store the location entry data in this format. How can I achieve that with set method not with update method, cause update method requires a collection and document to already exist, but in my case they will be automatically created based on uid of the logged in user.
Here is my code for the Map and sending data to firebase.
uploadLoacationEntryData(
locationName, fullAddress, visitTime, visitDate, entryDate) async {
Map<String, dynamic> locationMap = {
"locationName": locationName,
"fullAddress": fullAddress,
"visitTime": visitTime,
"visitDate": visitDate,
"entryDate": entryDate,
};
//await _locationEntryDA.setUserLocationEntry(locationMap);
await _locationEntryDA.updateUserLocationEntry(locationMap);}
Future setUserLocationEntry(locationMap) async {
return await _firestore
.collection("LocationEntry")
.doc(_auth.currentUser.uid)
.set({
"locationEntry": FieldValue.arrayUnion([locationMap])
});}
Future updateUserLocationEntry(locationMap) async {
return await _firestore
.collection("LocationEntry")
.doc(_auth.currentUser.uid)
.update({
"locationEntry": FieldValue.arrayUnion([locationMap])
});}
