2017-10-12 4 views
4

私は、ドキュメントには、このような方法を組織していますarangodb AQLネストされた配列内のオブジェクトの値を変更するにはどうすればよいですか?

{ 
    "email": "[email protected]", 
    "name": "tyler", 
    "address": { 
    "street": "Beijing Road", 
    "zip": 510000 
    }, 
    "likes": [ 
    "running", 
    { 
     "movie": "Star Wars" 
    } 
    ] 
} 

私は「映画」の値を変更することで問題を抱えています。 AQLで値を変更する方法を教えてください。

ありがとうございます!

答えて

2

次のクエリを実行する必要があります。私は説明の中にコメントとしてコメントを入れました。私の例では、ドキュメントがcollectionという名前のコレクションに存在している前提としています

FOR doc IN collection 
    /* any filter condition to find the document(s) in question. 
    you should make sure this uses an index if there is a substantial 
    number of documents in the collection */ 
    FILTER doc.name == 'tyler' 

    /* enumerate the old likes and return them as is if they are not 
    of type object or do not have a 'movie' attribute. If they are 
    objects and have a 'movie' attribute, patch them with a 'movie' 
    value of 'whatever' */ 
    LET newLikes = (
    FOR oldLike IN doc.likes 
     RETURN 
     (TYPENAME(oldLike) == 'object' && HAS(oldLike, 'movie')) ? 
      { movie: 'whatever' } : 
      oldLike 
) 

    /* finally update the matching document(s) with the new likes */ 
    UPDATE doc WITH { likes: newLikes } IN collection 
+0

あなたの詳細な答えをありがとうございました。 –

関連する問題