QueryDocumentSnapshot

QueryDocumentSnapshot

new QueryDocumentSnapshot()

A QueryDocumentSnapshot contains data read from a document in your Firestore database as part of a query. The document is guaranteed to exist and its data can be extracted with data() or get() to get a specific field.

A QueryDocumentSnapshot offers the same API surface as a DocumentSnapshot. Since query results contain only existing documents, the exists property will always be true and data() will never return 'undefined'.

Extends

Members

createTime

The time the document was created.

Overrides:
Example
```
let query = firestore.collection('col');

query.get().forEach(snapshot => {
  console.log(`Document created at '${snapshot.createTime.toDate()}'`);
});
```

exists

True if the document exists.

Inherited From:
Example
```
let documentRef = firestore.doc('col/doc');

documentRef.get().then((documentSnapshot) => {
  if (documentSnapshot.exists) {
    console.log(`Data: ${JSON.stringify(documentSnapshot.data())}`);
  }
});
```

id

The ID of the document for which this DocumentSnapshot contains data.

Inherited From:
Example
```
let documentRef = firestore.doc('col/doc');

documentRef.get().then((documentSnapshot) => {
  if (documentSnapshot.exists) {
    console.log(`Document found with name '${documentSnapshot.id}'`);
  }
});
```

readTime

The time this snapshot was read.

Inherited From:
Example
```
let documentRef = firestore.doc('col/doc');

documentRef.get().then(documentSnapshot => {
  let readTime = documentSnapshot.readTime;
  console.log(`Document read at '${readTime.toDate()}'`);
});
```

ref

A DocumentReference for the document stored in this snapshot.

Inherited From:
Example
```
let documentRef = firestore.doc('col/doc');

documentRef.get().then((documentSnapshot) => {
  if (documentSnapshot.exists) {
    console.log(`Found document at '${documentSnapshot.ref.path}'`);
  }
});
```

updateTime

The time the document was last updated (at the time the snapshot was generated).

Overrides:
Example
```
let query = firestore.collection('col');

query.get().forEach(snapshot => {
  console.log(`Document updated at '${snapshot.updateTime.toDate()}'`);
});
```

Methods

data() → {T}

Retrieves all fields in the document as an object.

Returns:
Type Description
T

An object containing all fields in the document.

Overrides:
Example
```
let query = firestore.collection('col');

query.get().forEach(documentSnapshot => {
  let data = documentSnapshot.data();
  console.log(`Retrieved data: ${JSON.stringify(data)}`);
});
```

get(field) → {*}

Retrieves the field specified by field.

Parameters:
Name Type Description
field string | FieldPath

The field path (e.g. 'foo' or 'foo.bar') to a specific field.

Returns:
Type Description
*

The data at the specified field location or undefined if no such field exists.

Inherited From:
Example
```
let documentRef = firestore.doc('col/doc');

documentRef.set({ a: { b: 'c' }}).then(() => {
  return documentRef.get();
}).then(documentSnapshot => {
  let field = documentSnapshot.get('a.b');
  console.log(`Retrieved field value: ${field}`);
});
```

isEqual(other) → {boolean}

Returns true if the document's data and path in this DocumentSnapshot is equal to the provided value.

Parameters:
Name Type Description
other *

The value to compare against.

Returns:
Type Description
boolean

true if this DocumentSnapshot is equal to the provided value.

Inherited From: