【发布时间】:2017-03-12 22:09:26
【问题描述】:
不确定我在这里做错了什么,但我正在尝试将文档插入到存储数据库 my-db 中的 my-documents 中,但这没有发生。
我创建了一个这样的文档客户端-
_endpointUri = new Uri(Properties.Settings.Default.DocumentDBEndpoint);
_privateKey = Properties.Settings.Default.DocumentDBKey;
_databaseName = Properties.Settings.Default.DocumentDBDatabase;
_collectionName = collectionName;
_collectionUri = UriFactory.CreateDocumentCollectionUri(_databaseName, _collectionName);
_documentClient = new DocumentClient(_endpointUri, _privateKey);
然后我尝试将一个文档插入到集合中。
public async Task Set(T document)
{
await _documentClient.CreateDocumentAsync(_collectionUri.ToString(), document);
}
我尝试传递_collectionUri 和toString,它们都做同样的事情。如果我逐步通过调试器,该集合 uri 的 toString 看起来像-
dbs/my-db/colls/my-documents
我已经尝试在通话中设置.ConfigureAwait(false),并且根本没有等待它。当然,当它没有被等待时,它会越界,但不会将任何文档添加到 my-documents 集合中。
我不确定我是否在使用 CreateDocumentAsync(也尝试过 UpsertDocumentAsync),因为不会引发错误。
鉴于我犯了什么错误,谁能从信息中看出?
编辑 在我使用 Azure 进行的测试中,我确实选择了将 DocumentDB 与 MongoDB Api 一起使用。这可能是相关的。由于我可以轻松地将其全部消除,因此我将使用 DocumentDB Api 重新创建它,看看是否能解决问题。
【问题讨论】:
-
创建兼容 MongoDB 的数据库不会影响您通过 DocumentDB 协议 + 相关 SDK 进行本机调用的能力。
标签: c# .net azure azure-cosmosdb