Docs: Schema option 'autoCreate' default
See original GitHub issuehttps://mongoosejs.com/docs/guide.html#autoCreate says:
Before Mongoose builds indexes, it calls
Model.createCollection()
to create the underlying collection in MongoDB ifautoCreate
is set to true.
In our setup, we are using the defaults for this as well as autoIndex.
I.e. we are using this:
autoIndex: true
(the default)
autoCreate: false
(the default)
Still when our mongoose code starts running and when e.g. db1.model('Proxy', proxySchema, 'proxy');
is called we can see this in the mongodb logs:
2021-12-16T18:16:17.245+0100 I STORAGE [conn95] createCollection: db1.proxy with generated UUID: 434da758-b375-4195-ab14-47f519c49458
2021-12-16T18:16:17.600+0100 I INDEX [conn95] build index on: db1.proxy properties: { v: 2, key: { time: -1 }, name: "time_-1", ns: "db1.mtasAlarms", background: true }
So from the logs, the collection is created. But the above text in the docs it should not be.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8
Top Results From Across the Web
Mongoose v6.8.1: Defaults
Your schemas can define default values for certain paths. If you create a new document without that path set, the default will kick...
Read more >Documentation: 15: 5.9. Schemas - PostgreSQL
Keep the default search path, and grant privileges to create in the public schema. All users access the public schema implicitly. This simulates...
Read more >Specifying a schema | BigQuery - Google Cloud
In the Explorer panel, expand your project and select a dataset. Expand the more_vert Actions option and click Open. In the details panel,...
Read more >86. Database Initialization - Spring
Spring Boot chooses a default value for you based on whether it thinks your database is embedded. It defaults to create-drop if no...
Read more >Schema and data type mapping in copy activity - Microsoft Learn
Such default mapping supports flexible schemas and schema drift ... If you want to create a templatized pipeline to copy large number of ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi
If anyone still facing this issue, Please make sure that
mongoose.set('autoIndex', false) and mongoose.set('autoCreate', false);
should have been set before any schema creationExample: This is incorrect. It will create the schema even if the flags are set as false
`
`
But this is correct: `
`
@thernstig no, that isn’t intentional. We’ll take a look and see if we can repro that.