Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
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
mongo-php-library
Commits
0536d51b
Commit
0536d51b
authored
Mar 30, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-84: Allow Collection::dropIndex() to accept an IndexInfo object
parent
857cfc84
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
5 deletions
+45
-5
apiargs-MongoDBCollection-method-dropIndex-param.yaml
...des/apiargs-MongoDBCollection-method-dropIndex-param.yaml
+4
-4
Collection.php
src/Collection.php
+2
-1
IndexInfo.php
src/Model/IndexInfo.php
+10
-0
DropIndexesFunctionalTest.php
tests/Operation/DropIndexesFunctionalTest.php
+29
-0
No files found.
docs/includes/apiargs-MongoDBCollection-method-dropIndex-param.yaml
View file @
0536d51b
arg_name
:
param
name
:
$indexName
type
:
string
type
:
string
| :phpclass:`MongoDB\\Model\\IndexInfo`
description
:
|
The name o
f the index to drop. View the existing indexes on the collecti
on
using the :phpmethod:`listIndexes() <MongoDB\\Collection::listIndexes>`
method.
The name o
r model object of the index to drop. View the existing indexes
on
the collection using the :phpmethod:`listIndexes()
<MongoDB\\Collection::listIndexes>`
method.
interface
:
phpmethod
operation
:
~
optional
:
false
...
...
src/Collection.php
View file @
0536d51b
...
...
@@ -29,6 +29,7 @@ use MongoDB\Driver\Exception\RuntimeException as DriverRuntimeException;
use
MongoDB\Exception\InvalidArgumentException
;
use
MongoDB\Exception\UnexpectedValueException
;
use
MongoDB\Exception\UnsupportedException
;
use
MongoDB\Model\IndexInfo
;
use
MongoDB\Model\IndexInfoIterator
;
use
MongoDB\Operation\Aggregate
;
use
MongoDB\Operation\BulkWrite
;
...
...
@@ -443,7 +444,7 @@ class Collection
* Drop a single index in the collection.
*
* @see DropIndexes::__construct() for supported options
* @param string
$indexName Index name
* @param string
|IndexInfo $indexName Index name or model object
* @param array $options Additional options
* @return array|object Command result document
* @throws UnsupportedException if options are not supported by the selected server
...
...
src/Model/IndexInfo.php
View file @
0536d51b
...
...
@@ -60,6 +60,16 @@ class IndexInfo implements ArrayAccess
return
$this
->
info
;
}
/**
* Return the index name to allow casting IndexInfo to string.
*
* @return string
*/
public
function
__toString
()
{
return
$this
->
getName
();
}
/**
* Return the index key.
*
...
...
tests/Operation/DropIndexesFunctionalTest.php
View file @
0536d51b
...
...
@@ -2,6 +2,7 @@
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Model\IndexInfo
;
use
MongoDB\Operation\CreateIndexes
;
use
MongoDB\Operation\DropIndexes
;
use
MongoDB\Operation\ListIndexes
;
...
...
@@ -88,6 +89,34 @@ class DropIndexesFunctionalTest extends FunctionalTestCase
}
}
public
function
testDropByIndexInfo
()
{
$info
=
new
IndexInfo
([
'v'
=>
1
,
'key'
=>
[
'x'
=>
1
],
'name'
=>
'x_1'
,
'ns'
=>
'foo.bar'
,
]);
$operation
=
new
CreateIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
[[
'key'
=>
[
'x'
=>
1
]]]);
$createdIndexNames
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
$this
->
assertSame
(
'x_1'
,
$createdIndexNames
[
0
]);
$this
->
assertIndexExists
(
'x_1'
);
$operation
=
new
DropIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
(),
$info
);
$this
->
assertCommandSucceeded
(
$operation
->
execute
(
$this
->
getPrimaryServer
()));
$operation
=
new
ListIndexes
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$indexes
=
$operation
->
execute
(
$this
->
getPrimaryServer
());
foreach
(
$indexes
as
$index
)
{
if
(
$index
->
getName
()
===
'x_1'
)
{
$this
->
fail
(
'The "x_1" index should have been deleted'
);
}
}
}
public
function
testSessionOption
()
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
...
...
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