为什么不能在rethinkdb中将对象附加到数组? [英] Why can't I append an object to an array in rethinkdb?

查看:90
本文介绍了为什么不能在rethinkdb中将对象附加到数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将对象附加到rethink中的数组中.这是我尝试附加的方式:

I am trying to append an object into an array in rethink. Here is how I am trying to append it:

rethink.table('shifts')
        .get(shiftId)
        .update(row => row("milestones").default([]).append({
            dateAchieved: "2017-01-01",
            phaseType: "TEST"
        })).run(rethinkConnection)

我得到的错误是:

first_error: 'Inserted value must be an OBJECT (got ARRAY):\n[\n\t{\n\t\t"dateAchieved":\t"2017-01-01",\n\t\t"phaseType":\t"TEST"\n\t}\n]',

我也尝试过相同的代码,但是删除了.default([]),它没有改变任何内容.

I also tried the same code about, but removed .default([]), which did not change anything.

我尝试注销row('milestones')是什么,这是结果:

I have tried logging out what row('milestones') is and this is the result:

var_15("milestone")

我期待看到一个数组.将对象添加到数组还需要什么?我该如何进行这项工作?

I was expecting to see an array. What else is necessary to add an object to an array? How do I make this work?

推荐答案

您需要使用非数组文档来更新文档.您的要求应该看起来像这样

You need to update document with a document not an array. Your reql should look like this

rethink.table('shifts')
  .get(shiftId)
  .update({
    milestones: rethink.row('milestones').append({
      dateAchieved: "2017-01-01",
      phaseType: "TEST"
    })
  })
  .run(rethinkConnection)

这是因为.append命令不会将数据提交到数据库,它仅返回内存中修改的数组

this is because the .append command does not commit data to the database it only returns an in memory modified array

这篇关于为什么不能在rethinkdb中将对象附加到数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆