Your Rails application can comunicate with CosmosDB via Mongo DB API. Therefore you can use Mongoid gem (Or Mongo Mapper) to comunicate with your CosmosDB database

the problem however is that unlike localhost mongo conection, you cannot just provide host, user, password and everything magicly works. You need to use the uri option and specify presigned “connection string” url that Azure generated for you

Now to obtain this “connection string” you need to use az cli.

  1. create cosmos table from Azure portal (web interface)
  2. install az cli, how to here and login az login
Given that your "resource group" is named `my-project`
And  your cosmos db account has name `my-awesome-cosmos`
Then run this:
az cosmosdb list-connection-strings --resource-group my-project --name my-awesome-cosmos

if you have no idea what those values are run az cosmosdb list and search for name (name of cosmos DB) and resourceGroup

Now you will have string like this:

  "connectionStrings": [
      "connectionString": "mongodb://",
      "description": "Default MongoDB Connection String"

copy the connectinoString value to mongoid.yml:

# config/mongoid.yml

        ssl: true
      uri: mongodb://
        connect_timeout: 15

# ...

And now you should be connected

If you are looking for automated solution check this file

Ruby solution?

Unfortunatelly during the time of writing this article Azure Ruby SDK is not mentioning anything about Cosmos DB => sdk cannot do operation on Cosmos.

Be sure to check this as this article may be out of date. As soon as I have ruby solution I’ll include it in this note

source of information:

Discussion on this Article/Note: