Skip to main content

MongoDB

Type: state.mongodb

Status: stable

Reference: https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-mongodb/ Connection options: https://www.mongodb.com/docs/manual/reference/connection-string/#std-label-connections-connection-options

Example

apiVersion: cra.diagrid.io/v1beta1
kind: Component
metadata:
name: <name>
spec:
type: state.mongodb
version: v1
metadata:
# The connection string to use. One of `server`, `host` or `connectionstring` is required.
- name: connectionString
value: "mongodb://mycompany.com:27017"
# The name of the collection to use. (Optional)
#- name: collectionName
# value: "daprCollection"
# The name of the database to use. (Optional)
#- name: databaseName
# value: "daprStore"
# Use this state store as the Workflows Store, it will enable the Workflows API. Defaults to `false`. (Optional)
#- name: enableWorkflow
# value: "false"
# Prefix added to keys in the state store. (Optional)
#- name: keyPrefix
# value: "appid"
# The timeout for the operation. (Optional)
#- name: operationTimeout
# value: "5s"
# By setting outboxDiscardWhenMissingState to true, Dapr discards the transaction if it cannot find the state in the database and does not retry. This setting can be useful if the state store data has been deleted for any reason before Dapr was able to deliver the message and you would like Dapr to drop the items from the pub/sub and stop retrying to fetch the state (Optional)
#- name: outboxDiscardWhenMissingState
# value: "false"
# For outbox. Sets the name of the pub/sub component to deliver the notifications when publishing state changes (Optional)
#- name: outboxPublishPubsub
# value: ""
# For outbox. Sets the topic that receives the state changes on the pub/sub configured with "outboxPublishPubsub". The message body will be a state transaction item for an insert or update operation (Optional)
#- name: outboxPublishTopic
# value: ""
# For outbox. Sets the pub/sub component used by Dapr to coordinate the state and pub/sub transactions. If not set, the pub/sub component configured with "outboxPublishPubsub" is used. This is useful if you want to separate the pub/sub component used to send the notification state changes from the one used to coordinate the transaction (Optional)
#- name: outboxPubsub
# value: "outboxPublishPubsub"
# The read concern to use (Optional)
#- name: readconcern
# value: "local"
# The write concern to use (Optional)
#- name: writeconcern
# value: "majority, 2"

Authentication profiles

Available authentication profiles:

  • Connection string

  • Username and password

Connection string

Authenticate using a connection string.

connectionString

Required - The connection string to use. One of server, host or connectionstring is required.

Example value: mongodb://mycompany.com:27017

Username and password

Authenticate using username, password and either server or host properties.

password

Required - The password of the user (applicable in conjunction with host)

Example value: password

username

Required - The username of the user to connect with (applicable in conjunction with host)

Example value: admin

host

The host to connect to. One of server or host is required.

Example value: mongo-mongodb.default.svc.cluster.local:27017

params

Additional parameters to use when connecting. The params field accepts a query string that specifies connection specific options as <name>=<value> pairs, separated by & and prefixed with ?. See the MongoDB manual for the list of available options and their use cases.

Example value: ?authSource=daprStore&ssl=true

server

The server to connect to, when using DNS SRV record. One of server or host is required.

Example value: server.example.com

Metadata

collectionName

The name of the collection to use.

Default value: daprCollection

Example value: daprCollection

databaseName

The name of the database to use.

Default value: daprStore

Example value: daprStore

enableWorkflow (bool)

Use this state store as the Workflows Store, it will enable the Workflows API. Defaults to false.

Example value: false

keyPrefix (string)

Prefix added to keys in the state store.

Default value: appid

Example value: appid

Allowed values:

  • appid

  • name

  • none

Documentation: https://docs.dapr.io/developing-applications/building-blocks/state-management/howto-share-state/

operationTimeout (duration)

The timeout for the operation.

Default value: 5s

Example value: 10s

outboxDiscardWhenMissingState (bool)

By setting outboxDiscardWhenMissingState to true, Dapr discards the transaction if it cannot find the state in the database and does not retry. This setting can be useful if the state store data has been deleted for any reason before Dapr was able to deliver the message and you would like Dapr to drop the items from the pub/sub and stop retrying to fetch the state

Default value: false

outboxPublishPubsub (string)

For outbox. Sets the name of the pub/sub component to deliver the notifications when publishing state changes

outboxPublishTopic (string)

For outbox. Sets the topic that receives the state changes on the pub/sub configured with "outboxPublishPubsub". The message body will be a state transaction item for an insert or update operation

outboxPubsub (string)

For outbox. Sets the pub/sub component used by Dapr to coordinate the state and pub/sub transactions. If not set, the pub/sub component configured with "outboxPublishPubsub" is used. This is useful if you want to separate the pub/sub component used to send the notification state changes from the one used to coordinate the transaction

Default value: outboxPublishPubsub

readconcern (string)

The read concern to use

Example value: local

Allowed values:

  • available

  • local

  • linearizable

  • majority

  • snapshot

writeconcern

The write concern to use

Example value: majority, 2