setDefaultCollectionOptions
On this page
Sets the defaults that are used when a collection is created implicitly by a write command for the current database.setDefaultCollectionOptions
.
Syntax
db.runCommand({setDefaultCollectionOptions: 1value : <document>|<null>})
Field |
Type |
Description |
---|---|---|
|
Document |
Specifies the options to set. |
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.
var options = db.runCommand({ getDefaultCollectionOptions: 1 }).value;options.shardKey = { Code: 1 };db.runCommand({ setDefaultCollectionOptions: 1, value: options });
Last modified: May 15, 2023