毎回わからなくなるし調べるのしんどいのでメモ
ドキュメントID
(Firestore 全般) 使えない文字列がある。
/ とか . とかは入れたらダメ。
ドキュメント ID に . と .. は使用しないでください。
ドキュメント ID に /(スラッシュ)は使用しないでください。
https://firebase.google.com/docs/firestore/best-practices?hl=ja#document_ids
なのでパスとかはそのまま使えない。
データ登録
基本
use Google\Cloud\Firestore\FirestoreClient;
$collection = 'test';
$documentId = 'id';
$db = new FirestoreClient();
$docRef = $db->collection($collection)->document($documentId);
$docRef->set([
'field1' => "aaaa",
'field2' => "bbbb"
]);
ドキュメントIDを指定せずに自動で振る
set ではなく add を使う
use Google\Cloud\Firestore\FirestoreClient;
$collection = 'test';
$db = new FirestoreClient();
$docRef = $db->collection($collection)->add([
'field1' => "aaaa",
'field2' => "bbbb"
]);