title: Cosmos DB - Delete Document with Python
body: <p>In <a href="https://stackoverflow.com/questions/46871925/cosmos-db-deleting-a-document">this SO question</a> I had learnt that I cannot delete a Cosmos DB document using SQL.</p>
  
  <p>Using Python, I believe I need the <code>DeleteDocument()</code> method. This is how I'm getting the document ID's that are required (I believe) to then call the <code>DeleteDocument()</code> method. </p>
  
  <pre><code># set up the client
  client = document_client.DocumentClient()
  
  # use a SQL based query to get a bunch of documents
  query = { 'query': 'SELECT * FROM server s' }
  result_iterable = client.QueryDocuments('dbs/DB/colls/coll', query, options)
  
  results = list(result_iterable);
  
  for x in range(0, len (results)):
      docID = results[x]['id']
  </code></pre>
  
  <p>Now, at this stage I want to call <code>DeleteDocument()</code>.
  The inputs into which are <code>document_link</code> and <code>options</code>.</p>
  
  <p>I can define <code>document_link</code> as something like</p>
  
  <pre><code>document_link = 'dbs/DB/colls/coll/docs/'+docID
  </code></pre>
  
  <p>And successfully call <code>ReadAttachments()</code> for example, which has the same inputs as <code>DeleteDocument()</code>.</p>
  
  <p>When I do however, I get an error...</p>
  
  <pre><code>The partition key supplied in x-ms-partitionkey header has fewer
  components than defined in the the collection
  </code></pre>
  
  <p>...and now I'm totally lost</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Following on from Jay's help, I believe I'm missing the <code>partitonKey</code> element in the options.</p>
  
  <p>In this example, I've created a testing database, it looks like this
  <a href="https://i.stack.imgur.com/sp8cP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sp8cP.png" alt="Screen grab from my Azure account"></a></p>
  
  <p>So I think my partition key is <code>/testPART</code></p>
  
  <p>When I include the <code>partitionKey</code> in the options however, no results are returned, (and so <code>print len(results)</code> outputs 0).</p>
  
  <p>Removing <code>partitionKey</code> means that results are returned, but the delete attempt fails as before.</p>
  
  <pre><code># Query them in SQL
  query = { 'query': 'SELECT * FROM c' }
  
  options = {}
  options['enableCrossPartitionQuery'] = True
  options['maxItemCount'] = 2
  options['partitionKey'] = '/testPART'
  result_iterable = client.QueryDocuments('dbs/testDB/colls/testCOLL', query, options)
  results = list(result_iterable)
  
  # should be &gt; 0
  print len(results)
  
  for x in range(0, len (results)):
      docID = results[x]['id']
      print docID
      client.DeleteDocument('dbs/testDB/colls/testCOLL/docs/'+docID, options=options)
      print 'deleted', docID
  </code></pre>