For a full overview of MongoDB and all my posts on it, check out my overview.
If you want to explicitly create a new collection in MongoDB rather than letting it be automatically created when an insert operation happens, you can do so using the
If you wanted to create a new collection called
podcasts, do the following:
createCollections can also take a second argument of a document describing a large number of options that can modify the collection. You can read up on them here but some of the more useful options include:
- Set a TTL for documents to be automatically removed after a set time has passed
- Set a maximum size for the collection
- Create validation rules to control what documents can exist in the collection