Open ronlinet opened 4 years ago
Speaking about it I have just tested the bellow snippet and it works. This one is deleting content older than 20 hours.
use Google\Cloud\Firestore\FirestoreClient;
use Kreait\Firebase\ServiceAccount;
use Morrislaptop\Firestore\Factory;
$serviceAccount = ServiceAccount::fromJsonFile( storage_path() . '/app/google-services.json');
$firestore = (new Factory)
->withServiceAccount($serviceAccount)
->createFirestore();
$documents = $firestore->collection('alerts')->documents(['pageSize' => 100]);
foreach ($documents as $document) {
$hourdiff = round((time() - strtotime($document['date']))/36000, 1);
if( $hourdiff > 20 ) //everything older than 20 hours will be deleted
{
$document->reference()->delete();
}
}
Thanks @ronlinet
This one delete a collection document by id ..
$collection = $this->firestore->collection('collection_name')->document( (int) $document->id );
$collection->delete();
Do you plan to include delete feature in the project ?