How to use maximum/minimum field transforms using node.js

Skip to first unread message

Scott Lawson

Aug 18, 2020, 8:37:49 PM8/18/20
to google-cloud-firestore-discuss
With the node.js library I can't see a way to utilize the maximum and minimum FieldTransforms as per this

All the others work by using firestore.FieldValue.increment, firestore.FieldValue.serverTimestamp() etc, but there doesn't seem to be an equivalent for minimum and maximum.

Anyone know the workaround?

Brian Chen

Aug 24, 2020, 3:45:42 PM8/24/20
to google-cloud-firestore-discuss
We currently don't have plans to add the feature to the server SDKs at the moment, but we'll revisit if there is sufficient developer feedback. In the meantime, you would have to read the field and manually perform the max/min operation yourself. Hope this helps!

Tracy Hall

Dec 8, 2020, 12:12:27 PM12/8/20
to google-cloud-firestore-discuss
Just curious - *if* there's an index on a field, would that not inherently indicate there *exists* a maximum and minimum inherently due to ordering?  Just in case some Firebaser was thinking about the feature...

Kato Richardson

Dec 8, 2020, 2:51:55 PM12/8/20
to Tracy Hall, google-cloud-firestore-discuss
Hi Tracy,

The min/max methods don't assign based on the min/max for the entire collection, just the value provided and the existing value in the database. If you're looking for min/max across the entire collection, that can done with something like orderBy(number).limitToLast(1).

You can of course recreate min/max transform by using a transaction; it's fairly straightforward.

☼, Kato

You received this message because you are subscribed to the Google Groups "google-cloud-firestore-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit


Kato Richardson | Developer Programs Eng | | 775-235-8398

Ville Virtanen

Aug 30, 2023, 4:06:44 AMAug 30
to google-cloud-firestore-discuss
We really would like to have this feature too to be able to do blind update to documents that contain timestamps (in numeric format) that we don't want to touch if those already exist. (But populate if non existent.)
Reply all
Reply to author
0 new messages