ArangoDB AQL: Update single object in embedded array

前端 未结 2 736
陌清茗
陌清茗 2020-12-10 05:15

I am trying to update the attribute on a json document in an embedded array using AQL. How do i update the \"addressline\" for \"home\" type address using AQL below?

<
2条回答
  •  醉梦人生
    2020-12-10 05:49

    ArangoDB now supports subset indexes. The following query is based on dothebarts answer:

    FOR document IN complexCollection
        FILTER document.subList[*].filterByMe == true LIMIT 1
        UPDATE document WITH {
            items: (
                FOR element IN document.subList
                    RETURN element.filterByMe == true
                         ? MERGE(element, { attributeToAlter: "the shiniest value"})
                         : element
            )
        } IN complexCollection
    

    Note: Don't forget to create a hash index on subList[*].filterByMe:

    db._collection('complexCollection')
        .ensureIndex({type:'hash',fields:['subList[*].filterByMe']});
    

提交回复
热议问题