title: Exception raised while inserting values into Azure COSMOS DB for MongDB API : Document does not contain shard key
body: <p>I have created a database in Azure: Azure Cosmos DB.  </p>
  
  <p>While creating the db, I have selected the Resource Group, given Account Name, API :  selected `Azure COSMOS DB for MongDB API and given rest of the required details and created the DB account.  </p>
  
  <p>Once the DB account is created , I have added a a DB <code>abc-test</code> in it and added a collection <code>abc-test-col</code>. While creating the collection I have given shard key as <code>id</code>.  </p>
  
  <p>Now I have created a console application to test the connectivity and write some value into the database.This is the code I have written.</p>
  
  <pre><code>class Program
      {
          static  void Main(string[] args)
          {
              try
              {
                  Console.WriteLine("Start Execution");
                  Program p = new Program();
  
                  IMongoCollection&lt;CollectionData&gt; collection = p.GetCollection();
  
                  CollectionData cd = new CollectionData();
                  cd.id = Guid.NewGuid().ToString();
                  cd.Value = 100;
  
  
                  Task insertjob = collection.InsertOneAsync(cd);
                  insertjob.Wait(); // exception raised here
  
                  Console.WriteLine("Inserted data");
                  Console.ReadLine();
              }
              catch(Exception ex)
              {
                  Console.WriteLine("Exception : " + ex.Message);
              }
          }
  
          private IMongoCollection&lt;CollectionData&gt; GetCollection()
          {
              try
              {
                  string mongDBName = "abc-test";
                  IMongoDatabase database;
                  string collectionName = "abc-test-col";
  
                  string connectionString = "Connection String"; // Copied the primary connection string.
                  MongoClientSettings settings = MongoClientSettings.FromUrl(
                    new MongoUrl(connectionString)
                  );
                  settings.SslSettings =
                    new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
                  var mongoClient = new MongoClient(settings);
  
                  database = mongoClient.GetDatabase(mongDBName);
  
                  return database.GetCollection&lt;CollectionData&gt;(collectionName);
              }
              catch (Exception ex)
              {
                  throw;
              }
          }
      }
  </code></pre>
  
  <p>When I run this , I'm getting an exception </p>
  
  <blockquote>
    <p>One or more errors occurred. (Command insert failed: document does not
    contain shard key.)</p>
  </blockquote>
  
  <p>I have added <code>id</code> in my CollectionData, but still it is giving this exception.<br>
  Any help as to why this is throwing this error.Am I missing something  </p>
  
  <p>Any help in this matter will be so helpful.</p>