0

I want to make the key value a floating point type when overwriting the map type in firestore with flutter/dart.

Possible with ".set" but not with ".update" How is it possible?

current output value(.update)
{"40"
 {"0":{"aaa" : "aaa", "bbb" : "bbb"}},
 {"5":{"ccc" : "ccc", "ddd" : "ddd"}}
}

Ideal output value(.set)
{"40.0":{"aaa" : "aaa", "bbb" : "bbb"},
{"40.5":{"ccc" : "ccc", "ddd" : "ddd"}
}

Below is the corresponding code.

final testRef = FirebaseFirestore.instance.collection("test").doc("test");
await testRef.update(
      {
        "40.0": {"aaa" : "aaa", "bbb" : "bbb"},
        "40.5" : {"ccc" : "ccc", "ddd" : "ddd"},
      }
    );
Ken White
  • 123,280
  • 14
  • 225
  • 444
24k
  • 27
  • 5

1 Answers1

0

In an update call a . is used as a field separator, so your code updates the 0 and 5 subfields of the top-level 40 field.

If you want to address a top-level field with a . in its name, you can create a FieldPath object to refer to it:

testRef.update({
  FieldPath(["40.0"]): {"aaa" : "aaa", "bbb" : "bbb"},
  FieldPath(["40.5"]): {"ccc" : "ccc", "ddd" : "ddd"},
});

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807