Uploading data type of Map or Array to Firestore database to match Firestore map and array type
7,250
I think this will work
Firestore.instance.collection('/mycollection').add({
'mapData' : myMap,
}).then((onValue) {
// do something
}).catchError((e) {
print(e);
});
Author by
Uma
Updated on December 02, 2022Comments
-
Uma over 1 year
I have a Map of type
Map<String, String>
and I am trying to upload it to Firestore to match the map datatype available as a field. See image below.I have tried using the toString method for the map class and assigning it to a field but it shows up as a long string rather than a map, see code snippet below
Firestore.instance.collection('/mycollection').add({ 'mapData' : myMap.toString(), // myMap.toString() = {data: test, data2: name} }).then((onValue) { // do something }).catchError((e) { print(e); });
The above snippet uploads the to string value of
myMap
as a string and assigns it tomapdata
. It does not send the data in the map format to FirestoreAny ideas on how to send a type of
Map<string, string>
to Firestore to map the type ofmap
that Firestore provides ? And also fromList
to Firestorearray
-
Doug Stevenson over 5 yearsI take it that you already tried to use
myMap
directly as the field value formapData
, and it didn't do what you expect? -
Uma over 5 yearsNah I didnt actually, I just did and it worked.
-
-
Doug Stevenson over 5 yearsThis will likely not create a field of type object as is shown in the screenshot. The document in the screenshot has a single field
thisMap
, and it contains an object with three properties. -
dshukertjr over 5 years@DougStevenson You are right. Missed the small detail. Let me rethink
-
Uma over 5 yearsYou were right, that actually worked, thank you, it sent it to the Firestore as a map
-
user1689987 almost 3 yearsI don't see a Map object