使用数组条目更新列;如果不存在则创建列

Update column with array entry; create column if it does not exist

                            r.table("bets").filter({id: betID}).update({
                                votes: r.row('votes').append({
                                    userID: userID,
                                    vote: vote
                                })
                            }).run(connection, function(err, result) {
                                // ...
                            });

我的目标是使用给定的 betID 更新 bets table 中的文档。我想更新可能不存在的列 votes。如果它不存在,我想创建列,然后追加数组元素。如果它存在,我只想追加数组元素。 result.replaced returns 1,这是正确的,但是未创建列 votes...知道吗?

找到解决方案:

                            var newVote = {
                                userID: userID,
                                vote: vote
                            };

                            r.table("bets").filter({id: betID}).update({
                                votes: r.row('votes').default([]).append(newVote)
                            }).run(connection, function(err, result) {

                            });

看看。 https://rethinkdb.com/api/javascript/update/