Table of Contents

Method CreateCollection

Namespace
MongoDB.Driver
Assembly
MongoDB.Driver.Legacy.dll

CreateCollection(string)

Creates a collection. MongoDB creates collections automatically when they are first used, so this command is mainly here for frameworks.

public virtual CommandResult CreateCollection(string collectionName)

Parameters

collectionName string

The name of the collection.

Returns

CommandResult

A CommandResult.

CreateCollection(string, IMongoCollectionOptions)

Creates a collection. MongoDB creates collections automatically when they are first used, so you only need to call this method if you want to provide non-default options.

public virtual CommandResult CreateCollection(string collectionName, IMongoCollectionOptions options)

Parameters

collectionName string

The name of the collection.

options IMongoCollectionOptions

Options for creating this collection (usually a CollectionOptionsDocument or constructed using the CollectionOptions builder).

Returns

CommandResult

A CommandResult.