首页 文章

具有指定标识或名称的资源已存在 - Dcoumentdb

提问于
浏览
0

我已经使用documentdb插入了两个json文档,并将它们放在名为Hotelwithroomtype的列表中 . 我想用一些新值更新创建的json文档,然后将它们重新创建为新文档 . 这是我的代码

foreach (var item in Hotelwithroomtype)
            {
                foreach (var cal in Calendardata)
                {

                    item.CalendarDate = Convert.ToDateTime(cal.CalendarDate);
                    item.CalendarDay = cal.Calendarday;
                    item.issweekday = Convert.ToBoolean(cal.isweekday);
                    item.issweekend = Convert.ToBoolean(cal.isweekend);

                    foreach (var prop in item.RoomTypes.RoomTypeList)
                    {

                        prop.Mon = "0";
                        prop.Tue = "0";
                        prop.Wed = "0";
                        prop.Thur = "0";
                        prop.Fri = "0";
                        prop.Sat = "0";
                        prop.Sun = "0";
                        prop.Count = "0";
                        prop.CountType = "0";

                    }
                   // var docExists = client.CreateDocumentQuery(UriFactory.CreateDocumentCollectionUri("next", "nextCollection"))
                   //.Where(doc => doc.Id == item.id)
                   //.Select(doc => doc.Id)
                   //.AsEnumerable()
                   //.Any();

                    await client.CreateDocumentAsync(collectionLink, item);

                }


            }

我插入的示例Json文档

{
"HotelCriteria": {
    "HotelCode": "101920",
    "HotelName": "TestThe Zuri"
},
"RoomTypes": {
    "RoomTypeList": [
        {
            "InvTypeCode": "ZCR",
            "Name": "Zuri Club Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 66,
            "IsRoomActive": 1,
            "RoomDescription": "",
            "Availability": 0,
            "Mon": "0",
            "Tue": "0",
            "Wed": "0",
            "Thur": "0",
            "Fri": "0",
            "Sat": "0",
            "Sun": "0",
            "CountType": "0",
            "Count": "0"
        },
        {
            "InvTypeCode": "ZRR",
            "Name": "Zuri Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 90,
            "IsRoomActive": 1,
            "RoomDescription": "",
            "Availability": 0,
            "Mon": "0",
            "Tue": "0",
            "Wed": "0",
            "Thur": "0",
            "Fri": "0",
            "Sat": "0",
            "Sun": "0",
            "CountType": "0",
            "Count": "0"
        },
        {
            "InvTypeCode": "ZSR",
            "Name": "Zuri Suite Room",
            "BaseOccupancy": 2,
            "MaxOccupancy": 3,
            "Quantity": 4,
            "IsRoomActive": 1,
            "RoomDescription": "",
            "Availability": 0,
            "Mon": "0",
            "Tue": "0",
            "Wed": "0",
            "Thur": "0",
            "Fri": "0",
            "Sat": "0",
            "Sun": "0",
            "CountType": "0",
            "Count": "0"
        }
    ]
},
"RatePlans": {
    "RatePlanList": [
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZCR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        },
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZRR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        },
        {
            "RatePlanCode": "B2C00001",
            "RatePlanCategory": "B2C",
            "RatePlanStatusType": 1,
            "RatePlanName": "Channel Rates",
            "Description": "Channel Rates",
            "InvTypeCode": "ZSR",
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan",
            "Start": "2016-06-27",
            "End": "2017-03-31",
            "CurrencyCode": "INR"
        }
    ]
},
"Inclusions": {
    "InclusionList": [
        {
            "MealPlanCode": "CP",
            "MealPlanDesc": "Continental Plan"
        }
    ]
},
"id": "8f236805-d3a5-498b-9cc3-efa7448faa63",
"_rid": "SVcZALakfQAEAAAAAAAAAA==",
"_self": "dbs/SVcZAA==/colls/SVcZALakfQA=/docs/SVcZALakfQAEAAAAAAAAAA==/",
"_etag": "\"00004b09-0000-0000-0000-594a02e80000\"",
"_attachments": "attachments/",
"_ts": 1498022618

}

我希望当前文档具有更新的值,但需要它们作为新文档 . 当我尝试创建时,我得到以下错误“具有指定ID或名称的资源已存在” . 任何帮助将非常感谢 .

谢谢

1 回答

  • 1

    您正在尝试使用 id 等于现有文档的 id 的新文档 . 这是不允许的,因此操作失败 . 在插入修改后的副本之前,需要为其分配一个新的 id .

相关问题