Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ResourceType Document is unexpected at UpsertDocumentAsync()

I'm new to Azure DocumentDB, and I've immediately run into a problem while trying it out. On the first save in an empty collection, I get the following error:

ResourceType Document is unexpected.

ActivityId: 29619975-e55a-4f31-a3d1-73d180ba3932

My repository code (partial) is as follows:

public interface IEntity
{
    string Id { get; set; }
    DateTime DbCreatedAt { get; set; }
    DateTime DbLastUpdatedAt { get; set; }
}

public class Repository<T>: IRepository<T> where T: class, IEntity
{
    private DocumentClient _documentClient;
    private string _databaseName;
    private string _collectionName;

    // ....
    // ....

    public Task SaveAsync(T entity)
    {
        var documentUri = UriFactory.CreateDocumentUri(_databaseName, _collectionName, entity.Id);
        return _documentClient.UpsertDocumentAsync(documentUri, entity);
    }
}

This is the first time anything has ever been written to this database/collection. Am I doing something wrong?

like image 703
Carvellis Avatar asked Feb 03 '17 16:02

Carvellis


1 Answers

UpsertDocumentAsync should take the DocumentCollection link, instead of Document link.

like image 125
Ming Liu Avatar answered Sep 28 '22 06:09

Ming Liu