Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Jenssegers/Mongodb/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ public function expire($columns, $seconds)
/**
* @inheritdoc
*/
public function create()
public function create($options = [])
{
$collection = $this->collection->getCollectionName();

$db = $this->connection->getMongoDB();

// Ensure the collection is created.
$db->createCollection($collection);
$db->createCollection($collection, $options);
}

/**
Expand Down
7 changes: 4 additions & 3 deletions src/Jenssegers/Mongodb/Schema/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ public function hasColumns($table, array $columns)
/**
* Determine if the given collection exists.
* @param string $collection
* @return bool
* @param bool $collection_info
* @return bool|\MongoDB\Model\CollectionInfo
*/
public function hasCollection($collection)
public function hasCollection($collection, $collection_info = false)
{
$db = $this->connection->getMongoDB();

foreach ($db->listCollections() as $collectionFromMongo) {
if ($collectionFromMongo->getName() == $collection) {
return true;
return $collection_info ? $collectionFromMongo : true;
}
}

Expand Down
4 changes: 4 additions & 0 deletions tests/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public function testCreateWithOptions(): void
Schema::create('newcollection_two', null, ['capped' => true, 'size' => 1024]);
$this->assertTrue(Schema::hasCollection('newcollection_two'));
$this->assertTrue(Schema::hasTable('newcollection_two'));

$collection = Schema::hasCollection('newcollection_two', true);
$this->assertTrue($collection['options']['capped']);
$this->assertEquals(1024, $collection['options']['size']);
}

public function testDrop(): void
Expand Down