Skip to content

Commit f12f766

Browse files
authored
Merge pull request #1330 from NoelDeMartin/fix-1318
#1318 Implement dropping all tables with mongo driver
2 parents 5d55933 + 8172bfb commit f12f766

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Jenssegers/Mongodb/Schema/Builder.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,36 @@ public function drop($collection)
106106
return $blueprint->drop();
107107
}
108108

109+
/**
110+
* @inheritdoc
111+
*/
112+
public function dropAllTables()
113+
{
114+
foreach ($this->getAllCollections() as $collection) {
115+
$this->drop($collection);
116+
}
117+
}
118+
109119
/**
110120
* @inheritdoc
111121
*/
112122
protected function createBlueprint($collection, Closure $callback = null)
113123
{
114124
return new Blueprint($this->connection, $collection);
115125
}
126+
127+
/**
128+
* Get all of the collections names for the database.
129+
*
130+
* @return array
131+
*/
132+
protected function getAllCollections()
133+
{
134+
$collections = [];
135+
foreach ($this->connection->getMongoDB()->listCollections() as $collection) {
136+
$collections[] = $collection->getName();
137+
}
138+
139+
return $collections;
140+
}
116141
}

0 commit comments

Comments
 (0)