Methods

arrayRemove

static

arrayRemove(...elements) returns FieldValue

Returns a special value that can be used with set(), create() or update() that tells the server to remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array.

Parameter

elements

any type

The elements to remove from the array.

Value may be repeated.

Returns

FieldValue 

The FieldValue sentinel for use in a call to set(), create() or update().

Example

let documentRef = firestore.doc('col/doc');

documentRef.update(
  'array', Firestore.FieldValue.arrayRemove('foo')
).then(() => {
  return documentRef.get();
}).then(doc => {
  // doc.get('array') no longer contains field 'foo'
});

arrayUnion

static

arrayUnion(...elements) returns FieldValue

Returns a special value that can be used with set(), create() or update() that tells the server to union the given elements with any array value that already exists on the server. Each specified element that doesn't already exist in the array will be added to the end. If the field being modified is not already an array it will be overwritten with an array containing exactly the specified elements.

Parameter

elements

any type

The elements to union into the array.

Value may be repeated.

Returns

FieldValue 

The FieldValue sentinel for use in a call to set(), create() or update().

Example

let documentRef = firestore.doc('col/doc');

documentRef.update(
  'array', Firestore.FieldValue.arrayUnion('foo')
).then(() => {
  return documentRef.get();
}).then(doc => {
  // doc.get('array') contains field 'foo'
});

delete

static

delete() returns FieldValue

Returns a sentinel for use with update() or set() with {merge:true} to mark a field for deletion.

Returns

FieldValue 

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' }
});

increment

static

increment(n) returns FieldValue

Returns a special value that can be used with set(), create() or update() that tells the server to increment the the field's current value by the given value.

If either current field value or the operand uses floating point precision, both values will be interpreted as floating point numbers and all arithmetic will follow IEEE 754 semantics. Otherwise, integer precision is kept and the result is capped between -2^63 and 2^63-1.

If the current field value is not of type 'number', or if the field does not yet exist, the transformation will set the field to the given value.

Parameter

n

number

The value to increment by.

Returns

FieldValue 

The FieldValue sentinel for use in a call to set(), create() or update().

Example

let documentRef = firestore.doc('col/doc');

documentRef.update(
  'counter', Firestore.FieldValue.increment(1)
).then(() => {
  return documentRef.get();
}).then(doc => {
  // doc.get('counter') was incremented
});

serverTimestamp

static

serverTimestamp() returns FieldValue

Returns a sentinel used with set(), create() or update() to include a server-generated timestamp in the written data.

Returns

FieldValue 

The FieldValue sentinel for use in a call to set(), create() or update().

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.