重新思考DB,将元素添加到嵌套的数组中

RethinkDB, add elements to an array that's nested

本文关键字:嵌套 数组 添加 元素 新思考 DB      更新时间:2023-09-26

使用这里的例子,我只在notes中添加了一个级别,它映射到一个对象,其元素本身包含数组

{
    id: 10001,
    name: "Bob Smith",
    notes: {
        alpha:['note1','note2','note3'],
        beta:['note1','note2','note3']
    }
}

然而,我一生都无法弄清楚如何将元素附加到alphabeta。我已经尝试了这个的变体:

update({ 
    notes:{  
        alpha: r.row("alpha").append('note4')  
    } 
})

但我真的一事无成。
任何帮助将不胜感激~

哦,错误消息No attribute 'alpha' in object:

您可以执行以下操作:

r.db('test')
 .table('user')
 .get('10001')
 .update({
   notes: {
     alpha: r.row('notes')('alpha').append('note4'),
     beta: r.row('notes')('beta').append('note4')
   }
 }).run();