LoginSignup
0
2

More than 3 years have passed since last update.

php で firestore 使うときのメモ

Posted at

毎回わからなくなるし調べるのしんどいのでメモ

ドキュメント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"
]);

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2