rethinkdbrethinkdb-javascript

Why can't I append an object in an array in Rethinkdb?


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

rethink('shifts')
        .get(shiftId)
        .update(row => row("milestones").default([]).append({
            dateAchieved: date,
            phaseType: phasetype.toUpperCase()
        })).run(rethinkConnection)

The error I get is this:

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ReqlQueryLogicError: Expected type TABLE but found DATUM:
"shifts" in:
r("shifts").get("5d1b607f-e670-4eb5-b873-6e800f8ae8f8").update(function(var_15) { return var_15("milestones").default([]).append({"dateAchieved": r.ISO8601("2012-04-12T06:00:00.000Z"), "phaseType": "PILOT"}); })
  ^^^^^^^^  

What does it mean that it is expecting a 'TABLE', but found a 'DATUM'? How do I get this to insert an object into the array?


Solution

  • You need to do

    rethink.table(“shifts”)
    

    Calling the rethink namespace with a string just returns an expression