title: Azure DocumentDB SDK Java: Problems while inserting single document with partition key
body: <p>I have a method in my code which is responsible for inserting single documents into cosmosDB. And it used to work fine when i used to insert document without specifying partitionId in <a href="https://msdn.microsoft.com/en-us/library/microsoft.azure.documents.client.requestoptions.aspx" rel="nofollow noreferrer">RequestOptions</a>:</p>
  
  <pre><code>public Document createOne(JSONObject aJSONObject)  throws DocumentClientException {
      Document aDocument = new Document(aJSONObject.toString());            
      return documentClient.createDocument(getCollectionLink(), aDocument, null, false).getResource();
  }
  </code></pre>
  
  <p>But if i change my code to pass partitionId in <code>RequestOptions</code> like this:</p>
  
  <pre><code>public Document createOne(JSONObject aJSONObject, String aPartitionKeyStr)  throws DocumentClientException {
      Document aDocument = new Document(aJSONObject.toString());
  
      PartitionKey aPartitionKey = new PartitionKey(aPartitionKeyStr);
      RequestOptions requestOptions = new RequestOptions();
      requestOptions.setPartitionKey(aPartitionKey);
  
      return documentClient.createDocument(getCollectionLink(), aDocument, requestOptions, false).getResource();
  }
  </code></pre>
  
  <p>I get the above error: <code>PartitionKey extracted from document doesn't match the one specified in the header</code>. I'm pretty sure i'm passing the partition key value correctly as i have the same <code>createMany</code> method which uses a stored procedure for bulk insertion and passes partitionKey in requestOptions, and it's working fine. I've looked up on internet and found similar questions that seemed to be related to my problem like <a href="https://stackoverflow.com/questions/43764755/partitionkey-extracted-from-document-doesnt-match-the-one-specified-in-the-head">this</a> and <a href="https://stackoverflow.com/questions/42919885/documentdb-rest-api-partitionkey-extracted-from-document-doesnt-match">this</a>, but they focus on passing the partitionKey correctly. I'm sure i'm passing the partitionKey correctly.</p>
  
  <p>In our collection, <code>/clientId</code> key is used as a partition key, setting the breakpoint at the first line of the insertion function gives this <a href="https://pastebin.com/MfDjTmUE" rel="nofollow noreferrer">output</a>, and aPartitionKey is printed as follows: <code>["shiv-postman-client"]</code> </p>
  
  <p>I have one more doubt, would passing partitionKey while inserting a single document would make any improvements in performance? I saw in azure's sdk documentation also <a href="https://github.com/Azure/azure-documentdb-java" rel="nofollow noreferrer">here</a>(the example that shows the partitioned collection usage), that they haven't used partition key while insertion, only during querying.</p>