Table of Contents

Method EnsureCreatedAsync

Namespace
MongoDB.EntityFrameworkCore
Assembly
MongoDB.EntityFrameworkCore.dll

EnsureCreatedAsync(DatabaseFacade, MongoDatabaseCreationOptions, CancellationToken)

Asynchronously ensures that the database for the context exists. If it exists, no action is taken. If it does not exist then the MongoDB database is created using the MongoDatabaseCreationOptions to determine what additional actions to take.

public static Task<bool> EnsureCreatedAsync(this DatabaseFacade databaseFacade, MongoDatabaseCreationOptions options, CancellationToken cancellationToken = default)

Parameters

databaseFacade DatabaseFacade

The DatabaseFacade from the EF Core DbContext.

options MongoDatabaseCreationOptions

An MongoDatabaseCreationOptions object specifying additional actions to be taken.

cancellationToken CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<bool>

A task that represents the asynchronous save operation. The task result contains true if the database is created, false if it already existed.