Returns document data as an array, or null if the document does not exist.
Example:
$data = $snapshot->data();
Returns
Type
Description
array|null
exists
Returns true if the document exists in the database.
Example:
if ($snapshot->exists()) {
echo "The document exists!";
}
Returns
Type
Description
bool
get
Get a field by field path.
A field path is a string containing the path to a specific field, at the
top level or nested, delimited by .. For instance, the value hello in
the structured field { "foo" : { "bar" : "hello" }} would be accessible
using a field path of foo.bar.
// Field names containing dots or symbols can be targeted using a FieldPath instance:
use Google\Cloud\Firestore\FieldPath;
$value = $snapshot->get(new FieldPath(['wallet', 'cryptoCurrency', 'my.coin']));
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[],[],null,["# Cloud Firestore Client - Class DocumentSnapshot (1.53.0)\n\nVersion latestkeyboard_arrow_down\n\n- [1.53.0 (latest)](/php/docs/reference/cloud-firestore/latest/DocumentSnapshot)\n- [1.52.0](/php/docs/reference/cloud-firestore/1.52.0/DocumentSnapshot)\n- [1.51.0](/php/docs/reference/cloud-firestore/1.51.0/DocumentSnapshot)\n- [1.50.0](/php/docs/reference/cloud-firestore/1.50.0/DocumentSnapshot)\n- [1.48.1](/php/docs/reference/cloud-firestore/1.48.1/DocumentSnapshot)\n- [1.47.3](/php/docs/reference/cloud-firestore/1.47.3/DocumentSnapshot)\n- [1.46.0](/php/docs/reference/cloud-firestore/1.46.0/DocumentSnapshot)\n- [1.45.2](/php/docs/reference/cloud-firestore/1.45.2/DocumentSnapshot)\n- [1.44.1](/php/docs/reference/cloud-firestore/1.44.1/DocumentSnapshot)\n- [1.43.3](/php/docs/reference/cloud-firestore/1.43.3/DocumentSnapshot)\n- [1.40.0](/php/docs/reference/cloud-firestore/1.40.0/DocumentSnapshot)\n- [1.39.0](/php/docs/reference/cloud-firestore/1.39.0/DocumentSnapshot)\n- [1.38.0](/php/docs/reference/cloud-firestore/1.38.0/DocumentSnapshot)\n- [1.37.7](/php/docs/reference/cloud-firestore/1.37.7/DocumentSnapshot)\n- [1.36.1](/php/docs/reference/cloud-firestore/1.36.1/DocumentSnapshot)\n- [1.35.0](/php/docs/reference/cloud-firestore/1.35.0/DocumentSnapshot)\n- [1.34.0](/php/docs/reference/cloud-firestore/1.34.0/DocumentSnapshot)\n- [1.33.0](/php/docs/reference/cloud-firestore/1.33.0/DocumentSnapshot)\n- [1.32.0](/php/docs/reference/cloud-firestore/1.32.0/DocumentSnapshot)\n- [1.31.0](/php/docs/reference/cloud-firestore/1.31.0/DocumentSnapshot)\n- [1.30.0](/php/docs/reference/cloud-firestore/1.30.0/DocumentSnapshot)\n- [1.28.0](/php/docs/reference/cloud-firestore/1.28.0/DocumentSnapshot)\n- [1.27.3](/php/docs/reference/cloud-firestore/1.27.3/DocumentSnapshot) \nReference documentation and code samples for the Cloud Firestore Client class DocumentSnapshot.\n\nRepresents the data of a document at the time of retrieval.\n\nA snapshot is immutable and may point to a non-existing document.\n\nFields may be read in array-style syntax. Note that writing using array-style\nsyntax is NOT supported and will result in a `\\BadMethodCallException`.\n\nExample: \n\n use Google\\Cloud\\Firestore\\FirestoreClient;\n\n $firestore = new FirestoreClient();\n $document = $firestore-\u003edocument('users/john');\n $snapshot = $document-\u003esnapshot();\n\n // Fields are exposed via array-style accessors:\n $bitcoinWalletValue = $snapshot['wallet']['cryptoCurrency']['bitcoin'];\n\nNamespace\n---------\n\nGoogle \\\\ Cloud \\\\ Firestore\n\nMethods\n-------\n\n### __construct\n\n### reference\n\nGet the reference of the document which created the snapshot.\n\nExample: \n\n $reference = $snapshot-\u003ereference();\n\n### name\n\nGet the document name.\n\nNames are absolute. The result of this call would be of the form\n`projects/\u003cproject-id\u003e/databases/\u003cdatabase-id\u003e/documents/\u003crelative-path\u003e`.\n\nOther methods are available to retrieve different parts of a collection name:\n\n- [DocumentSnapshot::id()](/php/docs/reference/cloud-firestore/latest/DocumentSnapshot#_Google_Cloud_Firestore_DocumentSnapshot__id__) Returns the last element.\n- [DocumentSnapshot::path()](/php/docs/reference/cloud-firestore/latest/DocumentSnapshot#_Google_Cloud_Firestore_DocumentSnapshot__path__) Returns the path, relative to the database.\n\nExample: \n\n $name = $snapshot-\u003ename();\n\n### path\n\nGet the document path.\n\nPaths identify the location of a document, relative to the database name.\n\nTo retrieve the document ID (the last element of the path), use\n[DocumentSnapshot::id()](/php/docs/reference/cloud-firestore/latest/DocumentSnapshot#_Google_Cloud_Firestore_DocumentSnapshot__id__).\n\nExample: \n\n $path = $snapshot-\u003epath();\n\n### id\n\nGet the document identifier (i.e. the last path element).\n\nIDs are the path element which identifies a resource. To retrieve the\nfull path to a resource (the resource name), use\n[DocumentSnapshot::name()](/php/docs/reference/cloud-firestore/latest/DocumentSnapshot#_Google_Cloud_Firestore_DocumentSnapshot__name__).\n\nExample: \n\n $id = $snapshot-\u003eid();\n\n### updateTime\n\nGet the Document Update Timestamp.\n\nExample: \n\n $updateTime = $snapshot-\u003eupdateTime();\n\n### readTime\n\nGet the Document Read Timestamp.\n\nExample: \n\n $readTime = $snapshot-\u003ereadTime();\n\n### createTime\n\nGet the Document Create Timestamp.\n\nExample: \n\n $createTime = $snapshot-\u003ecreateTime();\n\n### data\n\nReturns document data as an array, or null if the document does not exist.\n\nExample: \n\n $data = $snapshot-\u003edata();\n\n### exists\n\nReturns true if the document exists in the database.\n\nExample: \n\n if ($snapshot-\u003eexists()) {\n echo \"The document exists!\";\n }\n\n### get\n\nGet a field by field path.\n\nA field path is a string containing the path to a specific field, at the\ntop level or nested, delimited by `.`. For instance, the value `hello` in\nthe structured field `{ \"foo\" : { \"bar\" : \"hello\" }}` would be accessible\nusing a field path of `foo.bar`.\n\nExample: \n\n $value = $snapshot-\u003eget('wallet.cryptoCurrency.bitcoin');\n\n // Field names containing dots or symbols can be targeted using a FieldPath instance:\n use Google\\Cloud\\Firestore\\FieldPath;\n\n $value = $snapshot-\u003eget(new FieldPath(['wallet', 'cryptoCurrency', 'my.coin']));\n\n### offsetSet\n\n### offsetExists\n\n### offsetUnset\n\n### offsetGet"]]