FieldValue
Sentinel values that can be used when writing documents with set() or update().
Methods
delete
delete() returns any type
Returns a sentinel used with update() to mark a field for deletion.
- Returns
-
any type
The sentinel value to use in your objects.
Example
let documentRef = firestore.doc('col/doc');
let data = { a: 'b', c: 'd' };
documentRef.set(data).then(() => {
return documentRef.update({a: Firestore.FieldValue.delete()});
}).then(() => {
// Document now only contains { c: 'd' }
});
serverTimestamp
serverTimestamp() returns any type
Returns a sentinel used with set(), create() or update() to include a server-generated timestamp in the written data.
- Returns
-
any type
The sentinel value to use in your objects.
Example
let documentRef = firestore.doc('col/doc');
documentRef.set({
time: Firestore.FieldValue.serverTimestamp()
}).then(() => {
return documentRef.get();
}).then(doc => {
console.log(`Server time set to ${doc.get('time')}`);
});
isEqual
isEqual(other) returns boolean
Returns true if this FieldValue
is equal to the provided value.
Parameter |
|
---|---|
other |
any type The value to compare against. |
- Returns
-
boolean
true if this
FieldValue
is equal to the provided value.