Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
laravel-mongodb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
laravel-mongodb
Commits
3f5b1dc5
Unverified
Commit
3f5b1dc5
authored
Feb 17, 2020
by
Stas
Committed by
GitHub
Feb 17, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1953 from divine/pr_1745
[Updated PR#1745] Bugfix create collection with options
parents
6cea8aae
ae88c82d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
11 deletions
+35
-11
Blueprint.php
src/Jenssegers/Mongodb/Schema/Blueprint.php
+5
-3
Builder.php
src/Jenssegers/Mongodb/Schema/Builder.php
+26
-8
SchemaTest.php
tests/SchemaTest.php
+4
-0
No files found.
src/Jenssegers/Mongodb/Schema/Blueprint.php
View file @
3f5b1dc5
...
...
@@ -234,16 +234,18 @@ class Blueprint extends \Illuminate\Database\Schema\Blueprint
}
/**
* @inheritdoc
* Indicate that the collection needs to be created.
* @param array $options
* @return void
*/
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
);
}
/**
...
...
src/Jenssegers/Mongodb/Schema/Builder.php
View file @
3f5b1dc5
...
...
@@ -33,20 +33,20 @@ class Builder extends \Illuminate\Database\Schema\Builder
/**
* Determine if the given collection exists.
* @param string $
collection
* @param string $
name
* @return bool
*/
public
function
hasCollection
(
$
collection
)
public
function
hasCollection
(
$
name
)
{
$db
=
$this
->
connection
->
getMongoDB
();
foreach
(
$db
->
listCollections
()
as
$collectionFromMongo
)
{
if
(
$collectionFromMongo
->
getName
()
==
$collection
)
{
return
true
;
}
}
$collections
=
iterator_to_array
(
$db
->
listCollections
([
'filter'
=>
[
'name'
=>
$name
,
],
]),
false
);
return
false
;
return
count
(
$collections
)
?
true
:
false
;
}
/**
...
...
@@ -134,6 +134,24 @@ class Builder extends \Illuminate\Database\Schema\Builder
return
new
Blueprint
(
$this
->
connection
,
$collection
);
}
/**
* Get collection.
* @param string $name
* @return bool|\MongoDB\Model\CollectionInfo
*/
public
function
getCollection
(
$name
)
{
$db
=
$this
->
connection
->
getMongoDB
();
$collections
=
iterator_to_array
(
$db
->
listCollections
([
'filter'
=>
[
'name'
=>
$name
,
],
]),
false
);
return
count
(
$collections
)
?
current
(
$collections
)
:
false
;
}
/**
* Get all of the collections names for the database.
* @return array
...
...
tests/SchemaTest.php
View file @
3f5b1dc5
...
...
@@ -34,6 +34,10 @@ class SchemaTest extends TestCase
Schema
::
create
(
'newcollection_two'
,
null
,
[
'capped'
=>
true
,
'size'
=>
1024
]);
$this
->
assertTrue
(
Schema
::
hasCollection
(
'newcollection_two'
));
$this
->
assertTrue
(
Schema
::
hasTable
(
'newcollection_two'
));
$collection
=
Schema
::
getCollection
(
'newcollection_two'
);
$this
->
assertTrue
(
$collection
[
'options'
][
'capped'
]);
$this
->
assertEquals
(
1024
,
$collection
[
'options'
][
'size'
]);
}
public
function
testDrop
()
:
void
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment