Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Cosmos DB shard key for Mongo API

I'm migrating a very simple mongo DB (couple 100 entries) to Azure Cosmos DB. My app is based on node-js so I'm using mongoose as a mapper. Before it was really simple, define schema, query collection, finished.

Now when setting up a collection in cosmos db, I was asked about partion key and shard key. The first one I could ignore, but the last one was required. Quickly reading-up on that topic and understanding it was kind of partioning (again, which I do not need and want), I just chose _id as shard key.

Of course something does not work.

While find queries work just fine. Updating or insert records fail, below is the error:

MongoError: query in command must target a single shard key

Cosmos db (with the mongo API) was advertised to me as a drop-in replacement. Which clearly is not the case because I never needed to worry about such things in mongo, especially for such a small scale app/db.

So, can I disable sharding somehow? Alternatively, how can I define shard key and not worry about it at all going forward?

Cheers

like image 370
baouss Avatar asked Feb 18 '19 09:02

baouss


People also ask

How do I use Cosmos DB with MongoDB API?

On the New page, select Databases > Azure Cosmos DB. On the Select API option page, select Azure Cosmos DB API for MongoDB > Create. The API determines the type of account to create. Select Azure Cosmos DB API for MongoDB because you will create a collection that works with MongoDB in this quickstart.

Is Cosmos DB compatible with MongoDB?

The Azure Cosmos DB's API for MongoDB is compatible with MongoDB server version 3.6 by default for new accounts. The supported operators and any limitations or exceptions are listed below. Any client driver that understands these protocols should be able to connect to Azure Cosmos DB's API for MongoDB.


1 Answers

You could create a CosmosDB collection with maximum fixed storage of 10GB. In that case the collection will not have to be sharded because the storage is not scalable and you will not receive errors from CosmosDB. However, due to the minimum throughput of 400 you might have slightly higher costs.

like image 81
Roman Gherta Avatar answered Oct 20 '22 21:10

Roman Gherta