DocumentSnapshot
には、Firestore データベース内のドキュメントから読み取られたデータが含まれています。 .data()
または.get(<field>)
を使用してデータを抽出し、特定のフィールドを取得できます。
存在しないドキュメントを指すDocumentSnapshot
の場合、データ アクセスはすべて「未定義」を返します。 exists()
メソッドを使用すると、ドキュメントの存在を明示的に確認できます。
サイン:
export declare class DocumentSnapshot<AppModelType = DocumentData, DbModelType extends DocumentData = DocumentData>
コンストラクター
コンストラクタ | 修飾子 | 説明 |
---|---|---|
(コンストラクタ)() | DocumentSnapshot クラスの新しいインスタンスを構築します。 |
プロパティ
財産 | 修飾子 | タイプ | 説明 |
---|---|---|---|
ID | 弦 | ドキュメントの ID を提供するDocumentSnapshot のプロパティ。 | |
参照 | ドキュメントリファレンス<AppModelType、DbModelType> | DocumentSnapshot に含まれるドキュメントのDocumentReference 。 |
メソッド
方法 | 修飾子 | 説明 |
---|---|---|
データ() | ドキュメント内のすべてのフィールドをObject として取得します。ドキュメントが存在しない場合は、 undefined 返します。 | |
存在します() | スナップショットの場所にドキュメントが存在するかどうかを通知します。 | |
get(フィールドパス) | fieldPath で指定されたフィールドを取得します。ドキュメントまたはフィールドが存在しない場合は、 undefined 返します。 |
DocumentSnapshot.(コンストラクター)
DocumentSnapshot
クラスの新しいインスタンスを構築します。
サイン:
protected constructor();
DocumentSnapshot.id
ドキュメントの ID を提供するDocumentSnapshot
のプロパティ。
サイン:
get id(): string;
DocumentSnapshot.ref
DocumentSnapshot
に含まれるドキュメントのDocumentReference
。
サイン:
get ref(): DocumentReference<AppModelType, DbModelType>;
DocumentSnapshot.data()
ドキュメント内のすべてのフィールドをObject
として取得します。 。ドキュメントが存在しない場合は、 undefined
返します。
サイン:
data(): AppModelType | undefined;
戻り値:
AppModelType |未定義
ドキュメント内のすべてのフィールドを含むObject
、またはドキュメントが存在しない場合はundefined
。
DocumentSnapshot.exists()
スナップショットの場所にドキュメントが存在するかどうかを通知します。
サイン:
exists(): this is QueryDocumentSnapshot<AppModelType, DbModelType>;
戻り値:
これはQueryDocumentSnapshotです<AppModelType、DbModelType>
ドキュメントが存在する場合は true。
DocumentSnapshot.get()
fieldPath
で指定されたフィールドを取得します。 。ドキュメントまたはフィールドが存在しない場合は、 undefined
返します。
サイン:
get(fieldPath: string | FieldPath): any;
パラメーター
パラメータ | タイプ | 説明 |
---|---|---|
フィールドパス | 文字列 |フィールドパス | 特定のフィールドへのパス (「foo」または「foo.bar」など)。 |
戻り値:
どれでも
指定されたフィールドの場所にあるデータ、またはそのようなフィールドがドキュメントに存在しない場合は未定義のデータ。