Save File in DocumentDb with custom name

淺唱寂寞╮ 提交于 2020-01-05 11:04:29

问题


  1. I'm trying to save a XML file in DocumentDb in Json format. I have no problem in converting it and saving. All the conversion and saving are working fine.

  2. However when I store my Xml file the DocumentDB provides its own file name to the file. Eg; 8756b9b9-41ac-47ca-9f4c-abec60b318be.

But I want to save the file with my own custom name Eg; MyXmlFile1 or MyXmlFile2 etc;

How do I pass my custom name when saving the file? That is MyXmlFile1 or MyXmlFile2.

"jsontoStore" has the content of the file I want to store into DocumentDB. Code1: Storing without passing any file name.

await client.CreateDocumentAsync(documentCollection.SelfLink, jsontoStore);

Code2: Storing with custom file name but here I'm not able to pass my content that is "jsontostore"

document = await client.CreateDocumentAsync(documentCollection.SelfLink,
                            new Document
                            {
                                Id = "sample1" 
                            });

回答1:


I believe you are referring to the id of a document, since you mentioned the auto-generated GUID.

All documents must have an unique value in the id property (it is the primary key for the document). If an id is not provided at the time of document creation, DocumentDB will generate one for you.

The solution here is to simply set the id field with the name of your choice (e.g. MyXmlFile1, MyXmlFile2) after you convert your XML to JSON.



来源:https://stackoverflow.com/questions/30667987/save-file-in-documentdb-with-custom-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!