Reputation: 107
I am trying to query a subcollection in Google Firestore. My goal is to get all records with a startDate (stored in Google Firestore's Timestamp data type) after January 1st, 1970.
I am using the GoogleCloud Firestore PHP SDK to do so: http://googlecloudplatform.github.io/google-cloud-php/#/docs/cloud-firestore/v0.9.0/firestore/querysnapshot
Here is my code:
$config = array(
"projectId" => "xxx-test",
"keyFile" => json_decode(file_get_contents("/xxx/firebase_auth.json"), true)
);
$firestore = new FirestoreClient($config);
$collection = $firestore->collection("/clients/-LXXXXXX/trips");
$query = $collection->where("startDate", ">=", new Timestamp(new \DateTime("Thu Jan 1st 1970")));
var_dump($query->documents());
And I get this error:
Exception 'Google\Cloud\Core\Exception\BadRequestException' with message
'{
"message": "Document parent name \"projects\/xxx-test\/databases\/(default)\/documents\/\/clients\/-LXXXXXX\" lacks a collection id at index 53.",
"code": 3,
"status": "INVALID_ARGUMENT",
"details": []
}'
Any help is greatly appreciated.
Upvotes: 0
Views: 4020
Reputation: 42028
Collection pathing doesn't work that way:
$collection = $firestore->collection("clients")->document("-LXXXXXX")->collection("trips");
Upvotes: 3