使用自定义名称将文件保存到DocumentDb中 [英] Save File in DocumentDb with custom name

查看:434
本文介绍了使用自定义名称将文件保存到DocumentDb中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我尝试以Json格式将XML文件保存在DocumentDb中。我在转换和保存没有问题。

  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.

但是当我存储我的Xml文件时,DocumentDB会为文件提供自己的文件名。例如; 8756b9b9-41ac-47ca-9f4c-abec60b318be

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

但我想保存文件与我自己的自定义名称例如; MyXmlFile1 MyXmlFile2 等;

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

如何在保存文件时传递自定义名称?这是MyXmlFile1或MyXmlFile2。

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

jsontoStore具有我要存储到DocumentDB中的文件的内容。
Code1:存储而不传递任何文件名。

"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:使用自定义文件名存储,但是在这里我不能传递我的内容, 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" 
                            });


推荐答案

我相信你指的是<$ c $

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

所有文档在<$ c中必须有一个唯一的值$ c> id 属性(它是文档的主键)。如果在创建文档时未提供 id ,DocumentDB会为您生成一个。

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.

这里是在将XML转换为JSON之后,使用您选择的名称(例如MyXmlFile1,MyXmlFile2)简单地设置 id 字段。

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.

这篇关于使用自定义名称将文件保存到DocumentDb中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆