Tag: 蔚cosmosdb

CreateDocumentCollectionIfNotExistsAsync并不总是有效

如果它不存在,我正在尝试创建一个集合。 首先,我通过以下方式创建DocumentClient: public DocumentClient CreateClient(ConnectionPolicy connectionPolicy = null) { return new DocumentClient(new Uri(this.AccountEndpoint), this.AccountKey, connectionPolicy); } 现在我有了我的文档客户端(让我们称之为documentDbClient ),我尝试使用CreateDocumentCollectionIfNotExistsAsync : var documentDbClient = dbConnection.CreateClient(); await documentDbClient.CreateDocumentCollectionIfNotExistsAsync(UriFactory.CreateDatabaseUri(“mydatabase”), new DocumentCollection { Id = “testcollection” }); 现在,我希望这会在名为mydatabase数据库下创建一个名为testcollection的集合。 然而,没有任何反应。 没有创建集合,也没有抛出exception。 我想也许它只是很慢,所以我等了30分钟然后回到门户网站,看看我的collections是否已经制作完…… 它没有。 怎么了? UPDATE 好的,所以我发现如果我改变我试图创建的集合的名称,它就可以了。 我之前已经多次创建和删除了该集合,现在看来Azure无法在90%的时间内创建它。

DocumentDb在transactioncope中写入

我正在尝试使用DocumentDb写作交易的一部分,如下所示 – using (var scope = new TransactionScope) { //first transaction //write to document db //third transaction } 我观察到如果第三个事务失败,则不会回滚documentDb write,我仍然会在集合中看到该文档。 第一个事务(在这种情况下为NEventStore)完美回滚。 有谁知道DocumentDb是否支持TrnasactionScope。 如果我有嵌套交易怎么办? 谢谢! 编辑:所以看起来DocumentDb不支持TransactionScope,它对它们一无所知。 有没有办法让DocumentDb事务成为C#外部事务的一部分? 有没有人遇到过此用例? 编辑2:按照建议在此处跟进问题和答案

在documentDB中搜索substring

这是示例documentDB文档, 我想获得一个或多个科目失败的所有文件 我发现了类似的东西 SELECT * FROM students s JOIN c IN s.subjects WHERE c.result = “pass” 我想使用c#代码检索 { “id”: “0066a253-f042-4213-b06e-65b1ea1e49aa”, “name”: “Sunny”, “rollNo”: 123, “class”: “2nd”, “section”: “B”, “Department”: { “name”: “CSE”, “id”: “cse”, “subjects”: [ { “id”: “subject-1”, “marksObtained”: 66, “maxMarks”: 100, “result”: “pass” }, { “id”: “subject-2”, “marksObtained”: 56, “maxMarks”: 75, “result”: “pass” […]

如何从带有guid id的集合中进行选择?

我有这个带有guid id的集合。 当我使用Azure Query Explorer并在上面的combobox中选择了集合时,它可以: SELECT * FROM c 但是当我尝试选择它时(来自查询exlorer和c#代码): SELECT * FROM 357fa002-dc7d-4ede-935a-6a0c80cf9239 c 我明白了: 语法错误,无效数值标记’357fa002’。 我试过把它放在guid附近的引号(单引号和双引号)但没有成功.. Microsoft文档声明此集合ID不会破坏任何规则: https : //docs.microsoft.com/pl-pl/azure/documentdb/documentdb-create-collection 集合名称必须介于1到255个字符之间,并且不能包含/ \#? 或尾随空间 如何使用它的id查询此集合?

Azure DocumentDB十进制截断

我目前正在使用Azure DocumentDB来存储价格的产品数据。 几乎所有东西都工作得很好但现在我有一个问题,我从读取DocumentDB时截断我的小数(System.Decimal)。 比如这个价格: 输入价格:25.1132356547854257645454 将被截断为 DocumentDB价格:25.113235654785 由于我们使用同步机制来查找价格变化,这将导致价格变化,因为它不再是相同的价格。 我不知道如何改变DocumentDB的行为。 在最坏的情况下,我将不得不截断我的输入价格以防止这个问题,但我宁愿不这样做。 感谢帮助。

如何使用ASP.NET Web API在DocumentDB中创建和更新文档之间的关系

我是.NET和Azure的新手,我正在尝试创建一个简单的Web API,以帮助我学习。 我有两个DocumentDB文档集合。 每个集合中的文件定义如下: public class Log { [JsonProperty(PropertyName = “id”)] public string Id { get; set; } [JsonProperty(PropertyName = “studentName”)] public string StudentName { get; set; } [JsonProperty(PropertyName = “assignment”)] public string Assignment { get; set; } [JsonProperty(PropertyName = “dueDate”)] public DateTime DueDate { get; set; } [JsonProperty(PropertyName = “goal”)] public string Goal { […]

在Azure Cosmos DB中使用REST进行CRUD操作

我正在尝试使用REST对Azure Cosmos DB执行CRUD操作。 根据链接https://docs.microsoft.com/en-us/rest/api/documentdb/create-a-document我创建了我的有效负载并尝试在Opera浏览器中使用Restman进行测试。 以下是我的有效载荷详情 – 头 Authorization *************************** Content-Type application/query+json x-ms-date Tue, 05 Dec 2017 16:49:31 GMT x-ms-session-token Session x-ms-version 2017-02-22 身体 id sg4c828f-31f8-4db4-8e7c-e8bdff222dsg value { “id”: “AndersenFamily”, “LastName”: “Andersen”, “Parents”: [ { “FamilyName”: null, “FirstName”: “Thomas” }, { “FamilyName”: null, “FirstName”: “Mary Kay” } ], “Children”: [ { “FamilyName”: null, “FirstName”: “Henriette Thaulow”, […]

尝试连接到azure数据库突然停止工作,抛出exception

我在Azure函数(V2)中运行以下代码; new DocumentClient(new Uri(keys.dbEndPoint), keys.dbPrimaryKey); 直到今天,在localhost上的azure函数中运行良好,没有改变任何东西我现在得到以下exception: Data [IDictionary]:{System.Collections.ListDictionaryInternal} HResult [int]: – 2146233036 HelpLink [string]:null InnerException [Exception]:{System.NullReferenceException:对象引用未设置为对象的实例。}消息[string ]:“’Microsoft.Azure.Documents.UserAgentContainer’的类型初始化程序引发了exception。” Source [string]:“Microsoft.Azure.DocumentDB.Core”StackTrace [string]:“在Microsoft.Azure.Documents.Client.ConnectionPolicy..ctor上的Microsoft.Azure.Documents.UserAgentContainer..ctor()\ r \ n” ()\ r \ n在Microsoft.Azure.Documents.Client.ConnectionPolicy.get_Default()\ r \ n 在Microsoft.Azure.Documents.Client.DocumentClient.Initialize(Uri 1 desiredConsistencyLevel)\r\n at Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, Nullable ,ConnectionPolicy connectionPolicy,Nullable 1 desiredConsistencyLevel)\r\n at Microsoft.Azure.Documents.Client.DocumentClient..ctor(Uri serviceEndpoint, String authKeyOrResourceToken, ConnectionPolicy connectionPolicy, Nullable 1 desiredConsistencyLevel)\ […]

从DocumentDB查询POCO实体

我正在关注Microsoft测试DocumentDB的这篇博客文章 。 我创建了一个集合,并在我的应用程序中通过不同的POCO类插入了2个文档。 它创建了文档,但我无法将它们过滤回各自的POCO类。 我意识到我正在查询所有集合,因此它显然正在检索存储在该集合中的所有文档。 在查询时区分文档的最佳方法是什么,以便我可以按类型单独查询它们? 我可以在文档中添加一个类型字段,并且可以通过WHERE type=”user”获取,但我不确定我不能用users是文档类型的SELECT * FROM users (如果在DocumentDB中有这样的东西),不是一个集合。 以下是我创建文档的方法: var user1= new User() { UserTypeId = 0, UserName = “user1@hotmail.com”, Password = “12345”, PasswordSalt = “saltyPassword”, UserStatusId = 1, ProfilePhotoKey = “KJSY” }; await DocumentDBRepository.CreateItemAsync(user1); var client = new Client() { ClientName = “client1”, Secret = “rxPBsIVYya2Jg2ZHPNG8gL0P36TnutiBehvEFgk938M=”, Title = “Administration Front […]

使用不同的分区模式在Azure DocumentDB中创建集合

有一些示例代码使用Microsoft.Azure.DocumentDB在azure documentDB中创建集合。 但是,我找不到有关如何使用c#创建具有不同分区模式的集合的信息。 从门户网站,有两种模式:单一分区和分区。 使用Microsoft.Azure.DocumentDB创建集合时,我们可以使用其中一个吗?