Stay organized with collections
Save and categorize content based on your preferences.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2022-07-27 UTC.
[null,null,["Last updated 2022-07-27 UTC."],[],[],null,["- [firebase](/docs/reference/js/v8/firebase).\n- [firestore](/docs/reference/js/v8/firebase.firestore).\n- DocumentSnapshot\n\\\u003c T \\\u003e \nA `DocumentSnapshot` contains data read from a document in your Firestore\ndatabase. The data can be extracted with `.data()` or `.get(\u003cfield\u003e)` to\nget a specific field.\n\nFor a `DocumentSnapshot` that points to a non-existing document, any data\naccess will return 'undefined'. You can use the `exists` property to\nexplicitly verify a document's existence.\n\nType parameters\n\n-\n\n T\n\nIndex\n\nConstructors\n\n- [constructor](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#constructor)\n\nProperties\n\n- [exists](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#exists)\n- [id](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#id)\n- [metadata](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#metadata)\n- [ref](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#ref)\n\nMethods\n\n- [data](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#data)\n- [get](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#get)\n- [isEqual](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot#isequal)\n\nConstructors\n\nProtected constructor\n\n- new DocumentSnapshot ( ) : [DocumentSnapshot](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot)\n-\n\n Returns [DocumentSnapshot](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot)\n\nProperties\n\nexists \nexists: boolean \nProperty of the `DocumentSnapshot` that signals whether or not the data\nexists. True if the document exists.\n\nid \nid: string \nProperty of the `DocumentSnapshot` that provides the document's ID.\n\nmetadata \nmetadata: [SnapshotMetadata](/docs/reference/js/v8/firebase.firestore.SnapshotMetadata) \nMetadata about the `DocumentSnapshot`, including information about its\nsource and local modifications.\n\nref \nref: [DocumentReference](/docs/reference/js/v8/firebase.firestore.DocumentReference)\\\u003cT\\\u003e \nThe `DocumentReference` for the document included in the `DocumentSnapshot`.\n\nMethods\n\ndata\n\n- data ( options ? : [SnapshotOptions](/docs/reference/js/v8/firebase.firestore.SnapshotOptions) ) : T \\| undefined\n- Retrieves all fields in the document as an Object. Returns 'undefined' if\n the document doesn't exist.\n\n By default, `FieldValue.serverTimestamp()` values that have not yet been\n set to their final value will be returned as `null`. You can override\n this by passing an options object.\n\n Parameters\n -\n\n Optional options: [SnapshotOptions](/docs/reference/js/v8/firebase.firestore.SnapshotOptions) \n An options object to configure how data is retrieved from\n the snapshot (e.g. the desired behavior for server timestamps that have\n not yet been set to their final value).\n\n Returns T \\| undefined\n\n An Object containing all fields in the document or 'undefined' if\n the document doesn't exist.\n\nget\n\n- get ( fieldPath : string \\| [FieldPath](/docs/reference/js/v8/firebase.firestore.FieldPath) , options ? : [SnapshotOptions](/docs/reference/js/v8/firebase.firestore.SnapshotOptions) ) : any\n- Retrieves the field specified by `fieldPath`. Returns `undefined` if the\n document or field doesn't exist.\n\n By default, a `FieldValue.serverTimestamp()` that has not yet been set to\n its final value will be returned as `null`. You can override this by\n passing an options object.\n\n Parameters\n -\n\n fieldPath: string \\| [FieldPath](/docs/reference/js/v8/firebase.firestore.FieldPath) \n The path (e.g. 'foo' or 'foo.bar') to a specific field.\n -\n\n Optional options: [SnapshotOptions](/docs/reference/js/v8/firebase.firestore.SnapshotOptions) \n An options object to configure how the field is retrieved\n from the snapshot (e.g. the desired behavior for server timestamps that have\n not yet been set to their final value).\n\n Returns any\n\n The data at the specified field location or undefined if no such\n field exists in the document.\n\nisEqual\n\n- isEqual ( other : [DocumentSnapshot](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot) \\\u003c T \\\u003e ) : boolean\n- Returns true if this `DocumentSnapshot` is equal to the provided one.\n\n Parameters\n -\n\n other: [DocumentSnapshot](/docs/reference/js/v8/firebase.firestore.DocumentSnapshot)\\\u003cT\\\u003e \n The `DocumentSnapshot` to compare against.\n\n Returns boolean\n\ntrue if this `DocumentSnapshot` is equal to the provided one."]]
A
DocumentSnapshot
contains data read from a document in your Firestore database. The data can be extracted with.data()
or.get(<field>)
to get a specific field.For a
DocumentSnapshot
that points to a non-existing document, any data access will return 'undefined'. You can use theexists
property to explicitly verify a document's existence.