setDefaultCollectionOptions
Sets the defaults that are used when a collection is created implicitly by a write command for the current database. All the options supported by the createCollection
command can be modified using setDefaultCollectionOptions
.
Syntax
db.runCommand({ setDefaultCollectionOptions: 1 value : <document>|<null> })
Field | Type | Description |
---|---|---|
| Document | Specifies the options to set. When set to |
Example
The following example sets default collection options for the current database:
db.runCommand({ setDefaultCollectionOptions: 1, value: { rowstore: true, shardKey: { _id: 1 } }, });
To update only one option from the defaults while leaving others unchanged, you may need to run multiple commands. Here's an example:
var options = db.runCommand({ getDefaultCollectionOptions: 1 }).value; options.shardKey = { Code: 1 }; db.runCommand({ setDefaultCollectionOptions: 1, value: options });