toFirestoreUpdate method

Map<String, dynamic> toFirestoreUpdate({
  1. List<String>? fieldsToExclude,
})

Convert to Firestore document for UPDATE operations.

Only updates fields returned by getUpdateTimestampFields, and completely removes fields from getCreateTimestampFields to preserve original values.

Parameters:

  • fieldsToExclude: List of field names to exclude from the output.

Example:

await firestore.collection('posts')
  .doc(postId)
  .update(post.toFirestoreUpdate());

Implementation

Map<String, dynamic> toFirestoreUpdate({
  List<String>? fieldsToExclude,
}) {
  final json = toJson();
  return _processForContext(
    json,
    SerializationContext.firestore,
    isUpdate: true,
    fieldsToExclude: fieldsToExclude,
  );
}