apiargs-MongoDBDatabase-method-createCollection-option.yaml 6.76 KB
Newer Older
1 2 3 4
arg_name: option
name: autoIndexId
type: boolean
description: |
5 6
  Specify ``false`` to disable the automatic creation of an index on the ``_id``
  field.
7 8 9

  .. important::

10
     For replica sets, do not set ``autoIndexId`` to ``false``.
11

12 13 14 15
  .. deprecated:: 1.4
     This option has been deprecated since MongoDB 3.2. As of MongoDB 4.0, this
     option cannot be ``false`` when creating a replicated collection (i.e. a
     collection outside of the ``local`` database in any mongod mode).
16
interface: phpmethod
17
operation: ~
18 19 20 21 22 23
optional: true
---
arg_name: option
name: capped
type: boolean
description: |
24 25
  To create a capped collection, specify ``true``. If you specify ``true``, you
  must also set a maximum size in the ``size`` option.
26
interface: phpmethod
27
operation: ~
28
optional: true
29 30
---
source:
31
  file: apiargs-common-option.yaml
32 33 34 35
  ref: collation
pre: |
  Specifies the :manual:`collation
  </reference/bson-type-comparison-order/#collation>` for the collection.
36 37
---
arg_name: option
38
name: flags
39 40
type: integer
description: |
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  Available for the MMAPv1 storage engine only to set the ``usePowerOf2Sizes``
  and ``noPadding`` flags.

  The |php-library| provides constants that you can combine with a :php:`bitwise
  OR operator <language.operators.bitwise>` to set the flag values:

  - ``MongoDB\Operation\CreateCollection::USE_POWER_OF_2_SIZES``: ``1``
  - ``MongoDB\Operation\CreateCollection::NO_PADDING``: ``2``

  Defaults to ``1``.

  .. note::

     MongoDB 3.0 and later ignores the ``usePowerOf2Sizes`` flag. See
     :manual:`collMod </reference/command/collMod>` and
     :manual:`db.createCollection()
     </reference/method/db.createCollection>` for more information.
58
interface: phpmethod
59
operation: ~
60
optional: true
61 62
---
arg_name: option
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
name: indexOptionDefaults
type: array|object
description: |
  Allows users to specify a default configuration for indexes when creating a
  collection.

  The ``indexOptionDefaults`` option accepts a ``storageEngine`` document,
  which should take the following form::

     { <storage-engine-name>: <options> }

  Storage engine configurations specified when creating indexes are validated
  and logged to the :term:`oplog` during replication to support replica sets
  with members that use different storage engines.
interface: phpmethod
78
operation: ~
79 80 81
optional: true
---
arg_name: option
82 83 84
name: max
type: integer
description: |
85 86 87 88 89 90
  The maximum number of documents allowed in the capped collection. The ``size``
  option takes precedence over this limit. If a capped collection reaches the
  ``size`` limit before it reaches the maximum number of documents, MongoDB
  removes old documents. If you prefer to use the ``max`` limit, ensure that the
  ``size`` limit, which is required for a capped collection, is sufficient to
  contain the maximum number of documents.
91
interface: phpmethod
92
operation: ~
93
optional: true
94 95 96 97 98
---
source:
  file: apiargs-common-option.yaml
  ref: maxTimeMS
---
99 100 101
source:
  file: apiargs-common-option.yaml
  ref: session
102 103
post: |
  .. versionadded:: 1.3
104
---
105 106 107 108 109 110 111 112 113
arg_name: option
name: size
type: integer
description: |
  Specify a maximum size in bytes for a capped collection. Once a capped
  collection reaches its maximum size, MongoDB removes the older documents to
  make space for the new documents. The ``size`` option is required for capped
  collections and ignored for other collections.
interface: phpmethod
114
operation: ~
115
optional: true
116 117 118
---
arg_name: option
name: storageEngine
119
type: array|object
120 121 122 123 124 125 126 127 128 129 130 131 132
description: |
  Available for the WiredTiger storage engine only.

  Allows users to specify configuration to the storage engine on a
  per-collection basis when creating a collection. The value of the
  ``storageEngine`` option should take the following form::

     { <storage-engine-name>: <options> }

  Storage engine configurations specified when creating collections are
  validated and logged to the :term:`oplog` during replication to support
  replica sets with members that use different storage engines.
interface: phpmethod
133
operation: ~
134 135
optional: true
---
136
source:
137
  file: apiargs-MongoDBDatabase-common-option.yaml
138
  ref: typeMap
139 140
post: |
  This will be used for the returned command result document.
141 142 143 144 145 146
---
arg_name: option
name: validator
type: array
description: |
  Allows users to specify :manual:`validation rules or expressions
147 148 149
  </core/document-validation>` for the collection. For more information, see
  :manual:`Document Validation </core/document-validation>` in the MongoDB
  manual.
150

151 152 153 154 155
  The ``validator`` option takes an array that specifies the validation rules or
  expressions. You can specify the expressions using the same operators as
  MongoDB's :manual:`query operators </reference/operator/query>` with the
  exception of :query:`$geoNear`, :query:`$near`, :query:`$nearSphere`,
  :query:`$text`, and :query:`$where`.
156 157 158

  .. note::

159 160
     - Validation occurs during updates and inserts. Existing documents do not
       undergo validation checks until modification.
161 162 163 164 165

     - You cannot specify a validator for collections in the ``admin``,
       ``local``, and ``config`` databases.

     - You cannot specify a validator for ``system.*`` collections.
166
operation: ~
167 168 169 170
interface: phpmethod
optional: true
---
arg_name: option
171
name: validationAction
172 173
type: string
description: |
174 175 176 177 178 179 180
   Determines whether to ``error`` on invalid documents or just ``warn`` about
   the violations but allow invalid documents to be inserted.

   .. important::

      Validation of documents only applies to those documents as determined by
      the ``validationLevel``.
181 182 183 184

   .. list-table::
      :header-rows: 1

185
      * - ``validationAction``
186 187 188

        - Description

189
      * - ``"error"``
190

191 192
        - **Default**. Documents must pass validation before the write occurs.
          Otherwise, the write operation fails.
193

194
      * - ``"warn"``
195

196 197
        - Documents do not have to pass validation. If the document fails
          validation, the write operation logs the validation failure.
198
interface: phpmethod
199
operation: ~
200 201 202
optional: true
---
arg_name: option
203
name: validationLevel
204 205
type: string
description: |
206 207
   Determines how strictly MongoDB applies the validation rules to existing
   documents during an update.
208 209 210 211

   .. list-table::
      :header-rows: 1

212
      * - ``validationLevel``
213 214 215

        - Description

216
      * - ``"off"``
217

218
        - No validation for inserts or updates.
219

220
      * - ``"strict"``
221

222 223 224 225 226 227 228
        - **Default**. Apply validation rules to all inserts and all updates.

      * - ``"moderate"``

        - Apply validation rules to inserts and to updates on existing *valid*
          documents. Do not apply rules to updates on existing *invalid*
          documents.
229
interface: phpmethod
230
operation: ~
231
optional: true
232 233 234 235 236 237 238
---
source:
  file: apiargs-MongoDBDatabase-common-option.yaml
  ref: writeConcern
post: |
  This is not supported for server versions prior to 3.4 and will result in an
  exception at execution time if used.
239
...