2014-02-27 3 views
1

가 나는 josn는 "갱신"이라는했으며,이 같은 임베디드 목록 "의견"이 있습니다삽입 된 목록에서 항목을 제거하는 방법은 무엇입니까?

{ 
    id: "update/0", 
    //comments contains elements with type:comment 
    comments: [{ 
     id:"comment/0" 
     children:[{ 
        id:"comment/00", 
         children[...] 
        }] 
    }] 
} 

질문은이 :

1, How to remove an item from update's field:comments by ids "update/0" and 
    "comment/0"? 

2, How to remove an item from comment's field:children by ids "update/0"," 
    comment/0" and "comment/00"? 

답변

0
r.table("update").get("update/0").update(function(doc) { 
    return doc.merge({ 
     comments: doc("comments").concatMap(function(comment) { 
      return r.branch(
        comment("id").eq("comment/0"), 
        [], 
        [comment] 
      ) 
     }) 
    }) 
}) 

r.table("update").get("update/0").update(function(doc) { 
    return doc.merge({ 
     comments: doc("comments").map(function(comment) { 
      return r.branch(
        comment("id").eq("comment/0"), 
        comment.merge({ 
         children: comment("children").concatMap(function(child) { 
          return r.branch(
           child("id").eq("comment/00"), 
           [], 
           [child] 
         ) 
         }) 
        }), 
        comment 
      ) 
     }) 
    }) 
}) 

당신은 또한 할 수 deleteAt을 가진 그 하지만 여러 테이블에서 데이터를 분할하는 것을 고려해야합니다. 내 코멘트보기 How to update an item in a embedded list?

관련 문제