components-contrib icon indicating copy to clipboard operation
components-contrib copied to clipboard

How to use Cosmos DB when container name is only known at runtime?

Open remojansen opened this issue 2 years ago • 1 comments

I'm working on a SaaS solution, and the users are allowed to create workspaces. Each workspace uses several CosmosDB containers pre-fixed with the workspace ID:

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: invitations-store
  namespace: default
spec:
  type: state.azure.cosmosdb
  version: v1
  metadata:
  - name: url
    value: "https://xxxxxx.documents.azure.com:443/"
  - name: masterKey
    secretKeyRef:
      name: "cosmosMasterKey"
  - name: database
    value: "xxxxxx"
  - name: collection
    value: "<WORKSPACE-ID>.environments" <-- HERE
  - name: partitionKey
    value: "id"

Is there a way to connect to a container without declaring a component? Can the component be declared at runtime?

remojansen avatar Jul 20 '22 22:07 remojansen

I found a solution: Use partition keys instead of prefixed container names. However, could be able to use bindings that are only known at runtime be a real use case in some scenarios?

remojansen avatar Jul 21 '22 09:07 remojansen

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

dapr-bot avatar Aug 20 '22 09:08 dapr-bot

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

dapr-bot avatar Aug 27 '22 09:08 dapr-bot

would be nice if the collection name can be part of the metadata when invoking the component. i have multiple microservices and just want to have a single component to dapr and allow each microservice to define the collection. with the current approach need multiple components

ekjuanrejon avatar May 19 '23 11:05 ekjuanrejon