Find docs with no PartitionKey in Azure DocumentDb
by Frans Lytzen | 07/02/2017Note: This post is written for C#, I am not sure about the equivalent for other languages.
Details
var docCollection = new DocumentCollection()and you then try to save an instance of a class that looks like this:
{
Id = this.collectionName
};
docCollection.PartitionKey.Paths.Add("/partitionKey");
await docClient.CreateDocumentCollectionAsync(
UriFactory.CreateDatabaseUri(this.dbName),
docCollection);
public class MyItemthen you may expect to get an error. But, in fact, it will save just fine as I found out to my detriment after a major refactoring.
{
[JsonProperty("id")]
public string Id { get; set; }
public string SomeValue { get; set; }
}
How to read the document:
MyItem item = (dynamic)client.ReadDocumentAsync(
UriFactory.CreateDocumentUri(DbName, CollectionName, id),
new RequestOptions() {
PartitionKey = new PartitionKey(Undefined.Value)
})
.Result.Resource;
How to delete the document:
client.DeleteDocumentAsync(
UriFactory.CreateDocumentUri(DbName, CollectionName, id),
new RequestOptions() { PartitionKey = new PartitionKey(Undefined.Value) });