DocumentSnapshot class

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」など)。

戻り値:

どれでも

指定されたフィールドの場所にあるデータ、またはそのようなフィールドがドキュメントに存在しない場合は未定義のデータ。