public async Task AddAsync(T item, CancellationToken cancellationToken = default(CancellationToken))
        {
            bool create = false;

            try
            {
                await UpsertDocument(_docDBContext, item);
            }
            catch (Exception ex)
            {
                if (CosmosDBUtility.TryGetDocumentClientException(ex, out DocumentClientException de) &&
                    de.StatusCode == HttpStatusCode.NotFound)
                {
                    if (_docDBContext.ResolvedAttribute.CreateIfNotExists)
                    {
                        create = true;
                    }
                    else
                    {
                        // Throw a custom error so that it's easier to decipher.
                        string message = $"The collection '{_docDBContext.ResolvedAttribute.CollectionName}' (in database '{_docDBContext.ResolvedAttribute.DatabaseName}') does not exist. To automatically create the collection, set '{nameof(CosmosDBAttribute.CreateIfNotExists)}' to 'true'.";
                        throw new InvalidOperationException(message, ex);
                    }
                }
                else
                {
                    throw;
                }
            }

            if (create)
            {
                await CosmosDBUtility.CreateDatabaseAndCollectionIfNotExistAsync(_docDBContext);

                await UpsertDocument(_docDBContext, item);
            }
        }