Skip to content

Mongo DB

Entity Services support Read and Write Mongo DB components that can use Mongo (or Mongo compatible) database as data storage.

The database can be local MongoDB, MongoDB Atlas running in the cloud or Azure CosmosDB for MongoDB.

Configuraton

solutionName: "Axellon.Entity.Demo"
dataApi:
    entityGroups:
      - group: default

        readComponents:
          - type: MongoDbComponent

        writeComponents:
          - type: MongoDbComponent

        endpoints:
          - type: WebApiEndpoint

Connection string

The connection string that is used in generated solution can be defined in:

  • environment variable ConnectionStrings__MongoDBConnectionString,
  • appsettings.json file or
  • other sources of configuration values defined in the application.

The name of the config value can be changed in the generated repository project in SharedServiceRegistration.cs file.

Collections in Mongo DB

The application requires collections to be created in Mongo DB prior to running the application. Their names have to match the entities they store.

Azure CosmosDB for Mongo DB

The generated solution is fully compatible with Azure CosmosDB for MongoDB.

The easiest way to start using the application that uses Azure CosmosDB for storage is to create a CosmosDB account, MongoDB database and collections using the es-builder CLI command

es-builder deploy azure-mongodb

For all available parameters, check out the command description here.

Back to top