SetOptions class
Chooses whether a set call replaces the whole document or merges the
data into it.
Pass one to set of DocumentReference, WriteBatch or Transaction.
Without options, set replaces the document. With merge it changes only
the fields present in the data, and with mergeFields only the fields you
name. A merge creates the document if it does not exist.
final DocumentReference<Map<String, Object?>> sf = firestore.doc('cities/SF');
// Keeps every other field of the document.
await sf.set(<String, Object?>{'capital': false}, const SetOptions(merge: true));
// Writes only `population`, even though `name` is in the data too.
await sf.set(
<String, Object?>{'name': 'San Francisco', 'population': 870000},
const SetOptions(mergeFields: <String>['population']),
);
In a merge, nested maps are merged too: {'address': {'city': 'SF'}}
changes address.city and keeps the other fields of address. A merge
accepts FieldValue.delete to remove a field, which an overwrite does
not.
When the reference has a converter, FirestoreDataConverter.toFirestore
receives these options. In the JS SDK these are the {merge: true} and
{mergeFields: [...]} objects; this is FlutterFire's SetOptions.
SetOptions.merge and SetOptions.mergeFields are shorter ways to write the two forms.
Constructors
-
SetOptions({bool merge = false, List<
Object> ? mergeFields}) -
Options for a
setcall:mergemerges the data into the document, andmergeFieldsmerges only the fields it names. Give at most one of them; with neither,setreplaces the whole document.const - SetOptions.merge()
-
Options that merge the data into the document: the same as
SetOptions(merge: true).const -
SetOptions.mergeFields(List<
Object> fields) -
Options that merge only the fields in
fields(each a String path or a FieldPath): the same asSetOptions(mergeFields: fields).const
Properties
- hashCode → int
-
The hash code for this object.
no setteroverride
- merge → bool
-
Whether the data is merged into the existing document instead of
replacing it: true with
merge: trueand with mergeFields.no setter -
mergeFields
→ List<
FieldPath> ? -
The fields to merge, or null to merge every field of the data (with
merge) or to replace the document.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override