ahsankhatri / firestore-php

Firestore PHP Client (without gRPC extension)
MIT License
62 stars 57 forks source link

How to update document #31

Closed waqarfazal closed 3 years ago

waqarfazal commented 3 years ago

Hi! i'm trying to update the document using $firestoreClient->setDocument(). But it's giving me an error "The path you have defined is invalid. Path: categories". Please help me what i'm missing. Thank you Here is my code $collection = "categories"; $documentId = $id; $firestoreClient->setDocument($collection, $documentId, [ 'name' => $request->name, 'description' => $request->description, 'picture' => $filename, ], [ 'exists' => true, // Indicate document must exist ] );

waqarfazal commented 3 years ago

Found the solution I just gave the $collection parameter like "collection_name/document_id" & it worked. Thank you

Here is the working code $collection = "categories/".(string) $id; $firestoreClient->setDocument($collection, [ 'name' => $request->name, 'description' => $request->description, 'picture' => $filename, ], [ 'exists' => true, // Indicate document must exist ] );

waqarfazal commented 3 years ago

Solution found