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

30 views
Skip to first unread message

Scott Lawson

unread,
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 https://cloud.google.com/firestore/docs/reference/rest/v1/Write#FieldTransform

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

unread,
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

unread,
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

unread,
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 google-cloud-firestor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-firestore-discuss/1fc184e5-6d65-4e53-b512-1710d6af1385n%40googlegroups.com.


--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Ville Virtanen

unread,
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
Forward
0 new messages