Documentation

CreateCollection
in package

FinalYes

Operation for the create command.

Tags
see
Database::createCollection()
see
https://mongodb.com/docs/manual/reference/command/create/

Table of Contents

Properties

$collectionName  : string
$databaseName  : string
$options  : array<string|int, mixed>

Methods

__construct()  : mixed
Constructs a create command.
execute()  : void
Execute the operation.
createCommand()  : Command
Create the create command.
createOptions()  : array<string|int, mixed>
Create options for executing the command.

Properties

Methods

__construct()

Constructs a create command.

public __construct(string $databaseName, string $collectionName[, array<string|int, mixed> $options = [] ]) : mixed

Supported options:

  • capped (boolean): Specify true to create a capped collection. If set, the size option must also be specified. The default is false.

  • comment (mixed): BSON value to attach as a comment to this command.

    This is not supported for servers versions < 4.4.

  • changeStreamPreAndPostImages (document): Used to configure support for pre- and post-images in change streams.

    This is not supported for server versions < 6.0.

  • clusteredIndex (document): A clustered index specification.

    This is not supported for server versions < 5.3.

  • collation (document): Collation specification.

  • encryptedFields (document): Configuration for encrypted fields. See: https://www.mongodb.com/docs/manual/core/queryable-encryption/fundamentals/encrypt-and-query/

  • expireAfterSeconds: The TTL for documents in time series collections.

    This is not supported for servers versions < 5.0.

  • indexOptionDefaults (document): Default configuration for indexes when creating the collection.

  • max (integer): The maximum number of documents allowed in the capped collection. The size option takes precedence over this limit.

  • maxTimeMS (integer): The maximum amount of time to allow the query to run.

  • pipeline (array): An array that consists of the aggregation pipeline stage(s), which will be applied to the collection or view specified by viewOn.

  • session (MongoDB\Driver\Session): Client session.

  • size (integer): The maximum number of bytes for a capped collection.

  • storageEngine (document): Storage engine options.

  • timeseries (document): Options for time series collections.

    This is not supported for servers versions < 5.0.

  • validationAction (string): Validation action.

  • validationLevel (string): Validation level.

  • validator (document): Validation rules or expressions.

  • viewOn (string): The name of the source collection or view from which to create the view.

  • writeConcern (MongoDB\Driver\WriteConcern): Write concern.

Parameters
$databaseName : string

Database name

$collectionName : string

Collection name

$options : array<string|int, mixed> = []

Command options

Tags
see
https://source.wiredtiger.com/2.4.1/struct_w_t___s_e_s_s_i_o_n.html#a358ca4141d59c345f401c58501276bbb
see
https://mongodb.com/docs/manual/core/schema-validation/
throws
InvalidArgumentException

for parameter/option parsing errors

execute()

Execute the operation.

public execute(Server $server) : void
Parameters
$server : Server
Tags
throws
RuntimeException

for other driver errors (e.g. connection errors)

createCommand()

Create the create command.

private createCommand() : Command
Return values
Command

        
On this page

Search results