3

Using the latest azure cli (2.0.21) I am trying to create in CosmosDB a sharded MongoDB collection with the following script (from powershell) :

$resourceGroupName="RG-S01-APP-CASRWA-001"
$name="marcoolandesetest"
$databaseName="marco"
$collectionName="fromcli"
$originalThroughput=100000 
$kind="MongoDB"
$partition="/TaskId"

az login
az cosmosdb create --name $name --kind $kind --resource-group 
$resourceGroupName

az cosmosdb database create --name $name --db-name $databaseName --resource-
group $resourceGroupName 

az cosmosdb collection create --collection-name $collectionName --name $name --db-name $databaseName --resource-group $resourceGroupName --throughput $originalThroughput --partition-key-path $partition --indexing-policy '@index.json'

The content of the index.json is the following:

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                },
                {
                    "kind": "Hash",
                    "dataType": "String",
                    "precision": 3
                }
            ]
        }
    ],
    "excludedPaths": []
}

But when I try to insert a document from the UI in the portal nothing happens, the document hangs on inserting:

enter image description here

Inserting a document from a C# library with the MongoB.Drivers nuget package also fails, getting the error:

"document does not contain shard key"

obviously my document contains the shard key property "TaskId".

If I create the same kind of collection from the UI in the Portal everything works fine, also in C#, using the same code

Here are two screenshots of the settings of the collections, as you can see they are the same:

enter image description here

enter image description here Collection "fromui" is created from the portal UI, and with this one everything works fine, inserting a document from the portal, and inserting from C# as well.

Collection "fromcli" is created using the CLI script above and inserting a document it's not working at all.

2 Answers 2

2

Microsoft confirmed there is a bug in the CLI (2.0.21), they will soon roll out an update.

I created a blog post to describe how to solve this until a new CLI version will be release with a fix:

https://blog.olandese.nl/2017/12/13/create-a-sharded-mongodb-in-azure-cosmos-db/

1
  • Fixed my problem, thanks. Do you know if their fix will break code using this solution when it rolls out? May 4, 2018 at 18:38
0

Which browser do you use to create new document in the Portal? Could you please try to use another browser (Edge, Firefox, Chrome, Safari) or clean the browser cache completely and retry?

2
  • This behavior is not caused due a browser issue, this happens also from code, i.e. C#, it's a "server side" issue.
    – Olandese
    Dec 1, 2017 at 22:18
  • The part where you describe hanging "Creating new document" message in the browser is definitely a browser issue and is fixed by cleaning browser cache.
    – alekseys
    Dec 6, 2017 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.