Question: Hello my fellow coders!

I'm trying to use slide and fade simutaneously in jquery to make a "msg box" slide up and down, but i did not manage to make it wait (with `delay`) so the user can actually see the text in the msg box. I tried to put the `delay` call before `stop` but it doesnt work. Any ideas on how that can be done?

```
$('#msg_callout').stop(true, true)
                 .fadeIn({ duration: 'slow', queue: false })
                 .css('display', 'none').slideDown('slow', function () {

    $('#msg_callout').stop(true, true).delay(7000, function() {
        $(this).slideUp('slow').fadeOut({ duration: 'slow', queue: false });
    });
});

```

Thanks.

Answer: 
Sadly there is no other way, either you handle the exception or you make 2 calls, if you pick the second path, here is one performance-driven way of checking for document existence:

```
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(); //using Linq
}

```

The client should be shared among all your DB-accesing methods, but I created it there to have a auto-suficient example.

The `new FeedOptions () {MaxItemCount = 1}` will make sure the query will be optimized for 1 result (we don't really need more).

The `Select(x=>x.Id)` will make sure no other data is returned, if you don't specify it and the document exists, it will query and return all it's info.
With CosmosDB SDK ver. 3 it's possible. You can check if an item exists in a container and get it by using `Container.ReadItemStreamAsync<T>(string id, PartitionKey key)` and checking `response.StatusCode`:

```
using var response = await container.ReadItemStreamAsync(id, new PartitionKey(key));

if (response.StatusCode == HttpStatusCode.NotFound)
{
    return null;
}

if (!response.IsSuccessStatusCode)
{
    throw new Exception(response.ErrorMessage);
}

using var streamReader = new StreamReader(response.Content);

var content = await streamReader.ReadToEndAsync();

var item = JsonConvert.DeserializeObject(content, stateType);

```

This approach has a drawback, however. You need to deserialize the item by hand.