samuelgozi / firebase-firestore-lite

A lightweight cloud firestore library for the browser
MIT License
210 stars 12 forks source link

how can I implement the functionality of "firebase.firestore.FieldValue" using this library? #52

Closed alitecsolucoes closed 3 years ago

alitecsolucoes commented 3 years ago

Can I use these features available in the official library:

const ref = db.ref('users/samuel');

await ref.update({
    count: firebase.firestore.FieldValue.increment(1),
    last: firebase.firestore.FieldValue.serverTimestamp()
});

to increment a value without reading the document and store the server timestamp to the document?

Thank you very much in advance for the excellent work in these libraries!!

alijuniorbr commented 3 years ago

You can use:

import Transform from 'firebase-firestore-lite/src/Transform.js'

const ref = db.ref('users/samuel');

await ref.update({
    count: new Transform('increment', 1),
    last: new Transform('serverTimestamp')
});

as well documented in https://samuelgozi.github.io/firebase-firestore-lite/classes/transform.html

samuelgozi commented 3 years ago

@alijuniorbr Gave the right answer :) Thanks you!