Skip to content

Instantly share code, notes, and snippets.

@Red-Folder
Last active September 13, 2016 20:55
Show Gist options
  • Save Red-Folder/c2208f7d5ab8a6ea1694e0fbfdc2d119 to your computer and use it in GitHub Desktop.
Save Red-Folder/c2208f7d5ab8a6ea1694e0fbfdc2d119 to your computer and use it in GitHub Desktop.
Adding an index to a DocumentDB collection
DocumentClient client;
client = new DocumentClient(new Uri(endpointUri), primaryKey);
DocumentCollection resultCollection = client.ReadDocumentCollectionAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName)).Result;
resultCollection.Id = collectionName;
resultCollection.IndexingPolicy.IncludedPaths.Clear();
resultCollection.IndexingPolicy.IncludedPaths.Add(
new IncludedPath
{
Path = "/timestamp/?",
Indexes = new Collection<Index> {
new RangeIndex(DataType.String) { Precision = -1 }
}
});
resultCollection.IndexingPolicy.IncludedPaths.Add(
new IncludedPath
{
Path = "/*",
Indexes = new Collection<Index> {
new HashIndex(DataType.String) { Precision = 3 },
new RangeIndex(DataType.Number) { Precision = -1 }
},
});
client.ReplaceDocumentCollectionAsync(resultCollection).Wait();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment