SetOptions constructor

const SetOptions({
  1. bool merge = false,
  2. List<Object>? mergeFields,
})

Options for a set call: merge merges the data into the document, and mergeFields merges only the fields it names. Give at most one of them; with neither, set replaces the whole document.

Each entry of mergeFields is a String (a dot-separated field path, so 'address.city' names city inside the map address) or a FieldPath (for a field name that contains a dot). The set call throws an ArgumentError if an entry is not a valid field path or if the data has no value for one of the fields.

await firestore.doc('cities/SF').set(
  <String, Object?>{
    'stats.v2': <String, Object?>{'visits': 10},
  },
  SetOptions(mergeFields: <Object>[
    FieldPath(<String>['stats.v2', 'visits']),
  ]),
);

Implementation

const SetOptions({bool merge = false, List<Object>? mergeFields})
  : assert(
      !(merge && mergeFields != null),
      "SetOptions cannot have both 'merge' and 'mergeFields'.",
    ),
    _merge = merge,
    _mergeFields = mergeFields;