public function deleteFileById($id) { if ($id instanceof \MongoId) { $result = $this->getMongoCollection()->delete($id); } else { try { $result = $this->getMongoCollection()->delete(new \MongoId($id)); } catch (\MongoException $e) { $result = $this->getMongoCollection()->delete($id); } } if ($result['ok'] !== (double) 1) { throw new Exception('Error deleting file: ' . $result['err'] . ': ' . $result['errmsg']); } return $this; }
public function testDeleteById_MongoIdString() { $id = $this->gridFs->storeBytes('somebinarydata', array('meta1' => 1, 'meta2' => 2)); $this->gridFs->deleteFileById((string) $id); $this->assertEquals(null, $this->gridFs->getFileById($id)); }