这是我更新的文档,当我第一次执行查询结果是Result1时,我又一次执行查询结果是Result2。
查询:
UPDATE default AS d SET e.contact = ARRAY_APPEND(e.contact,{“email”:“sri123@gmail.com”,“phone”:9876655555}) FOR e IN d.details当e.id = 1234 END时 WHERE META()。id =“k01”;
结果1:
"k01":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34@gmail.com",
"phone": 6789435634
}
]
}]
}
结果2:
"k01":
{
"details": [
{
"id": 1234,
"city": "Medway",
"country": "United Kingdom",
"name": "Medway Youth Hostel",
"url": "http://www.yha.org.uk",
"contact": [
{
"email": "hari34@gmail.com",
"phone": 6789435634
},
{
"email": "hari34@gmail.com",
"phone": 6789435634
}
]
}]
}
如何控制重复值,当我第二次使用相同的值执行查询时。无论元素是否存在,每个字段都插入相同的值。请建议我(查询)。这样就不会发生重复的追加
答案 0 :(得分:0)
UPDATE default AS d SET e.contact = ARRAY_APPEND(e.contact,{“email”:“sri123@gmail.com”,“phone”:9876655555})FOR e IN d.details当e.id = 1234时END WHERE META()。id =“k01”AND ANY e IN d.details SATISFIES e.id = 1234 AND {“email”:“sri123@gmail.com”,“phone”:9876655555}不在e.contact END ;
如果联系人没有更新,那么这个更好。
OR
UPDATE default AS d SET e.contact = ARRAY_DISTINCT(ARRAY_APPEND(e.contact,{“email”:“sri123@gmail.com”,“phone”:9876655555}))e e in d.details e。 id = 1234 END WHERE META()。id =“k01”;
UPDATE default AS d SET e.contact = ARRAY_APPEND(e.contact,{“email”:“sri123@gmail.com”,“phone”:9876655555})FOR e IN d.details当e.id = 1234时AND {“email”:“sri123@gmail.com”,“phone”:9876655555}不在e.contact END WHERE META()。id =“k01”;
这会导致更新甚至联系人。