RethinkDB,将元素添加到嵌套的数组中
RethinkDB, add elements to an array that's nested
使用示例 here,我只向 notes
添加了一个级别,它映射到一个对象,其元素本身包含数组
{
id: 10001,
name: "Bob Smith",
notes: {
alpha:['note1','note2','note3'],
beta:['note1','note2','note3']
}
}
然而,我终究无法弄清楚如何将元素附加到 alpha
和 beta
。我试过这个的变体:
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();
使用示例 here,我只向 notes
添加了一个级别,它映射到一个对象,其元素本身包含数组
{
id: 10001,
name: "Bob Smith",
notes: {
alpha:['note1','note2','note3'],
beta:['note1','note2','note3']
}
}
然而,我终究无法弄清楚如何将元素附加到 alpha
和 beta
。我试过这个的变体:
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();