create
Explicitly creates this collection.
MongoDB will automatically create a collection with default settings on the first write operation. This method is useful to create a collection with non-default settings.
If this method is called and the collection already exists with the same options, nothing happens. If this method is called and the collection already exists with different options, an error is thrown.
Example
Create a capped collection: a collection with a maximum size on disk:
database.collection<Log>("logs")
.create {
capped(sizeBytes = 1024 * 1024) // 1 MiB
}Content copied to clipboard