简体   繁体   English

DocumentDB从不创建文档

[英]DocumentDB Never Creates Document

Not sure what I'm doing wrong here, but I'm trying to insert a document into my-documents in the storage database my-db but this isn't happening. 不知道我在这里做错了什么,但是我试图在存储数据库my-db my-documents中插入一个文档,但这没有发生。

I create a document client like this- 我创建这样的文档客户端-

  _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);

I then try to insert a document into the collection. 然后,我尝试将文档插入集合中。

public async Task Set(T document)
{
  await _documentClient.CreateDocumentAsync(_collectionUri.ToString(), document);
}

I tried passing the _collectionUri as well as the toString and they both do the same thing. 我尝试传递_collectionUri以及toString ,它们都做相同的事情。 If I step through the debugger the toString of that collection uri looks like- 如果我逐步通过调试器,则该集合uri的toString看起来像-

dbs/my-db/colls/my-documents dbs / my-db / colls / my-documents

I've tried set .ConfigureAwait(false) on the call, as well as not awaiting it at all. 我尝试在呼叫中设置.ConfigureAwait(false) ,以及根本不等待它。 Of course when it's not awaited it steps over the line fine, but no document ever gets added to the my-documents collection. 当然,当不等待它时,它会跳过行,但没有文档被添加到my-documents集合中。

I'm not sure if i'm using CreateDocumentAsync (also tried UpsertDocumentAsync ) because not errors are thrown. 我不确定我是否正在使用CreateDocumentAsync(也尝试过UpsertDocumentAsync ),因为不会引发错误。

Can anyone see from the information given what mistake I'm making? 鉴于我犯了什么错误,任何人都可以从信息中看到吗?

Edit In my testing with Azure I did opt to use DocumentDB with MongoDB Api. 编辑在与Azure的测试中,我确实选择将DocumentDB与MongoDB Api一起使用。 That may be related. 这可能是相关的。 Since I can easily blow it all away I will recreate it using the DocumentDB Api and see if that fixes the problem. 由于我可以轻松地将其全部销毁,因此我将使用DocumentDB Api重新创建它,并查看是否可以解决问题。

This turned out to be two different problems I assumed were the same. 原来这是我认为相同的两个不同问题。

Document Not Creating- 文档未创建-

So I set this up originally to use the MongoDB driver which dumped my databases/collections in Azure Storage. 因此,我最初将其设置为使用MongoDB驱动程序,该驱动程序将我的数据库/集合转储到Azure存储中。 The issue of the documents never getting created was because DocumentDB doesn't store itself in the Azure Storage resource. 从未创建文档的问题是因为DocumentDB不会将自身存储在Azure存储资源中。 When you create a new DocumentDB look under Settings > Collections > Browse to see that no databases exist. 创建新的DocumentDB时,请在“设置”>“集合”>“浏览”下查看是否不存在数据库。 Unfortunately it doesn't appear DocumentDB has a desktop db management application and this needs to be done on the azure portal. 不幸的是,它似乎没有DocumentDB具有桌面数据库管理应用程序,而这需要在azure门户上完成。

So the issue was, plainly, that the database/collection I was pointing to didn't exist for the above reason. 因此,问题显然是由于上述原因,我指向的数据库/集合不存在。

Await Never Returning- 等待永不返回-

Apparently if you're going to await something you need to await all the way through the call stack. 显然,如果您要等待某些事情,则需要一直等待整个调用堆栈。

(async) POST:Api (awaits) -> (async) Service:CreateDocument -> (async) Repository:Set (awaits) -> (async) DocumentClient:CreateDocumentAsync (async) POST:Api (awaits) -> (async) Service:CreateDocument -> (async) Repository:Set (awaits) -> (async) DocumentClient:CreateDocumentAsync

The problem was that even though my service was async, it was not awaiting the call to Repository:Set . 问题是,即使我的服务是异步的,它也没有等待Repository:Set的调用。 Awaiting everything up the chain allowed me to step-through and receive a response from the server. 等待链中的所有内容,使我可以逐步完成并收到服务器的响应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM