what is "field transformations" in Firestore?

Viewed 90

While I'm reading the limits of transactions, I found this:

Maximum number of field transformations that can be performed on a single document in a Commit operation or in a transaction : 500

but what is a "field transformations"? I can't find any information about this.

Does it mean when you use FieldValue.* for a field? If it is, how many operations counted in the following code?

var batch = db.batch();
var cityRef = db.collection('cities').doc('BJ');

batch.update(cityRef, {
    population: firebase.firestore.FieldValue.increment(50)
    _capital: firebase.firestore.FieldValue.delete(),
    f1: 'foobar',
    f2: 'foobarbaz',
});

batch.commit().then(() => {
    // ...
});

Does it count as three operations?

  1. FieldValue.increment
  2. FieldValue.delete
  3. the update() it self.
1 Answers

Field transformations are operations that transform a field between what is submitted from the client, and what is written into the storage layer of the database.

The current field transformations that the protocol knows of are in the definition of the FieldTransform type. The most common field transformations from there are:

FieldTransform Explanation
setToServerValue The server-side timestamp, in which case the client writes a so-called sentinel, and the server then transforms that into the timestamp.
increment The request to increment/decrement a field, which case the clients writes the amount to increment/decrement and the server transforms the existing value and the delta into the new value.
appendMissingElements The arrayUnion operation, in which case the client sends a value to be added to an array-field if it doesn't already exist in there, and the server performs the requested union.
removeAllFromArray The arrayRemove operation, in which case the client sends a value to be removed from an array-field, and the server removes all instances of that value.

There are two more field transformations (maximum, minimum), but I don't think those are exposed in any SDKs yet.

From this list it seems that deleting a field is not consider a field transformation, and thus the code in your question performs only one such transformation.

Related