Azure CosmosDB emulator errors "query in command must target a single shard key"

110 views Asked by At

I need help to make the emulator behave the same as the cosmos DB when using a custom shard key. The emulator expects the shard key to be in the filter argument when calling the following golang mongo driver API. Otherwise, it will returns error code 61 with message "query in command must target a single shard key"

func (c *collection) replaceDocument(ctx context.Context, filter Filter, doc Document, upsert bool) (bool, error) {

The same code behave correctly on Azure cosmos DB. Below is the document schema I used. I filter on the unique _id only when calling the above API.

{
   "_id": ==> unique non NULL key,
   "shard_key": ==> non NULL string field for sharding,
   other fields,
}
1

There are 1 answers

0
akg179 On

The CosmosDB emulator provides an emulation of CosmosDB service that runs on local workstation. This could result into differences between the emulator behavior versus the service account behavior. More information can be read here.