MongoIndexHelper
Creates indexes or anything like that at deploy time.
trait MongoIndexHelperuse MongoHelperRequires the mongodb/mongodb composer package to be installed.
- Copyright
- 2015-2016 Appertly
- License
- Apache-2.0
Instance Methods
| Returns | Signature and Description |
|---|---|
ConstVector<string> | createIndexes(, , , )Creates some indexes in a collection. |
ConstVector<mixed> | dropIndexes(, , , )Deletes some indexes in a collection. |
Ta | Makes sure a document isn't null. |
UTCDateTime | now()Gets the current time. |
?UTCDateTime | toDate()Tries to parse a date. |
ObjectID | toId()Transforms a literal into a MongoDB ObjectId. |
ConstVector<ObjectID> | toIds()Transforms literals into MongoDB ObjectIds. |
Method Details
createIndexes
createIndexes(Manager $manager, string $db, string $collection, ConstVector<MongoIndex> $indexes)Creates some indexes in a collection.
| Name | Type | Description |
|---|---|---|
$manager | Manager | The MongoDB manager |
$db | string | The database name |
$collection | string | The collection name |
$indexes | ConstVector<MongoIndex> | The indexes to create |
| Type | Description |
|---|---|
ConstVector<string> | The names of the created indexes |
| Type | Conditions |
|---|---|
Unreachable | If the connection fails |
Unretrievable | If the document doesn't exist |
Violating | If a constraint is violated |
Inoperable | If an API is used incorrectly |
Generic | If any other database problem occurs |
dropIndexes
dropIndexes(Manager $manager, string $db, string $collection, ConstSet<string> $names)Deletes some indexes in a collection.
This method will first check for the existence of the supplied indexes and if found, will drop them.
| Name | Type | Description |
|---|---|---|
$manager | Manager | The MongoDB manager |
$db | string | The database name |
$collection | string | The collection name |
$names | ConstSet<string> |
| Type | Description |
|---|---|
ConstVector<mixed> | The names of the created indexes |
| Type | Conditions |
|---|---|
Unreachable | If the connection fails |
Unretrievable | If the document doesn't exist |
Violating | If a constraint is violated |
Inoperable | If an API is used incorrectly |
Generic | If any other database problem occurs |
ensure
Inherited from MongoHelper
ensure<Ta>(mixed $id, ?Ta $document)Makes sure a document isn't null.
| Name | Type | Description |
|---|---|---|
$id | mixed | The document identifier, either a |
$document | ?Ta | The document to check |
| Type | Description |
|---|---|
Ta | Returns |
| Type | Conditions |
|---|---|
Unretrievable | if the document is null |
now
Inherited from MongoHelper
now()Gets the current time.
| Type | Description |
|---|---|
UTCDateTime | The current time |
toDate
Inherited from MongoHelper
toDate(mixed $date)Tries to parse a date.
| Name | Type | Description |
|---|---|---|
$date | mixed | The possible string date value, a string, a |
| Type | Description |
|---|---|
?UTCDateTime | The MongoDB datetime or null |
toId
Inherited from MongoHelper
toId(mixed $id)Transforms a literal into a MongoDB ObjectId.
| Name | Type | Description |
|---|---|---|
$id | mixed | If it's an |
| Type | Description |
|---|---|
ObjectID | The ObjectID |
toIds
Inherited from MongoHelper
toIds(ConstVector<mixed> $ids)Transforms literals into MongoDB ObjectIds.
| Name | Type | Description |
|---|---|---|
$ids | ConstVector<mixed> | Goes through each entry, converts to |
| Type | Description |
|---|---|
ConstVector<ObjectID> | The ObjectIDs |