Unfortunately, there is no other way: either you handle the exception, or make 2 calls if you choose the second path, here is one way to check for the existence of a document:
public bool ExistsDocument(string id) { var client = new DocumentClient(DatabaseUri, DatabaseKey); var collectionUri = UriFactory.CreateDocumentCollectionUri("dbName", "collectioName"); var query = client.CreateDocumentQuery<Microsoft.Azure.Documents.Document>(collectionUri, new FeedOptions() { MaxItemCount = 1 }); return query.Where(x => x.Id == id).Select(x=>x.Id).AsEnumerable().Any();
The client should be split between all your DB-accesing methods, but I created it there to have an autosave example.
new FeedOptions () {MaxItemCount = 1} will ensure that the request is optimized for 1 result (we really don't need any more).
Select(x=>x.Id) guarantees that no other data will be returned, if you do not specify it and the document exists, it will request and return all the information.
source share