Manage Partition Key in Azure Cosmos DB with C# SDK - azure-cosmosdb

Is there any way to manage an Azure Cosmos DB collection with partition key that uses the Mongo API directly from c#?
Currently we use Terraform to provision the Cosmos DB account and the database and we use the MongoDB.Driver to administrate collections. To get the Collection (and create it if it does not exist), we use the following syntax:
public IMongoCollection<MyDocument> MyDocumentsCollection =>
Database.GetCollection<MyDocument>("MyDocuments", mongoCollectionSetting);
I do not see any option to set the partition key for the collection and I was expecting to accomplish this with the mongoCollectionSettings. What is the best option to get this working?
I have found the Microsoft.Azure.Cosmos SDK but this is only applicable for Cosmos DB's SQL API.
Also I don't want to start with the method RunCommand but I guess this is the only option...?! Is it?

Related

Cosmos DB hybrid data APIs access (MongoDB & Gremin)

Is it possible to add data with the MongoDB APIs, then add edges between the documents with Gremlin, and query the same data with both APIs?
This is not possible today due to MongoDB's use of BSON which is not standard JSON. It is technically possible however to have SQL and Gremlin API within Cosmos DB.

Where is the primary key in the Cosmos DB GUI?

I'm new to Azure CosmosDB NoSQL. I have created a new account and a new Cosmos DB. I'm following this tutorial. I can't seem to find the config.key as it is in the image:
I guess it is not an up to date tutorial. What I have:
I have found the URI (which is not in the keys section), but where is the primary key?
As you have pointed out, you use Azure CosmosDB NoSQL while the first picture is Core (SQL) type of account.
And the second picture you provided is using Azure Cosmos Db for Mongo DB API in API attribute. So, to connect Mongo DB, you just need to use Primary Connection String.

How do I change API in cosmosDB?

I have a cosmosDB with mongo API, however there are many features not supported in this API so I want to switch to SQL API?
As things stand today it is not possible to switch you account from one type to another.
This is what you need to do if you need to switch to the SQL API:
Create a SQL API Cosmos DB Account
Download the Cosmos DBmigration tool
Migrate all the data from the MongoDB account to the SQL API account
Delete the MongoDB account

Restrict user access to Azure CosmosDB MongoDB Database

Azure CosmosDB - MongoDB provides keys for Read-Write and Read Only at account level.
CosmosDB SDK and API are there through which users can be created and access can be define at database and document level.
• But What I need to do is to create a pair of username and password with restricted access to a MongoDB database similar to one provided by installable MongoDB.
• How a user can connect only CosmosDB MongoDB database using RoboMongo.
Highly appreciate any help.
Amit -
Today, Cosmos DB access are provided by using two keys, Master Key and Read Only key. However, if you want to restrict user access per collection, per document etc, you have to use Resource Tokens. You can read more about it here and please take a look at CH9 video to see the implementation details. Resource Token service can be implemented as an Azure Function. Here is code to get you started.
But if you are using RoboMongo you have to Use the keys as define in this document. At this time you cannot define different users and Keys for a Database.

Creating a Graph Collection with an existing CosmosDB Account

I have an existing CosmosDB Account which was originally set up for the SQL api. I would like to create a graph but keep/manage it under the same database account.
I would like to use the Gremlin.Net sdk which (if I understand properly) requires the 'https://my-account.gremlin.cosmosdb.azure.com:443/' endpoint. Do all collections have this endpoint, or only collections created with an account targeting the gremlin api?
A better way of doing this would be
Create a new Graph account ( this will create the required gremlin server endpoint)
Migrate existing data using graph bulk executor.
Jayanta

Resources