rethinkDB: get first key name in an object

Viewed 41

I'm just starting with rethinkDB query lang and don't understand how to select the first key (name). In this case I would be the object notes.

I did it with Object.keys(t)[0]; tries that just returns me args, what am I doing wrong?

{
    id: "mission@0",
    info:
      "Tokyo",
    **//how to get the value of content ?**
    note: {
      "note@032b8836-f647-4165-9ec9-fc22769f3ffa": {
        content: "hello world",
        context: "all",
        glyphId: "glyph@default",
        id: "note@032b8836-f647-4165-9ec9-fc22769f3ffa",
        meta: {
          context: null,
          createdAt: 1624044683953,
          id: "note@032b8836-f647-4165-9ec9-fc22769f3ffa",
          links: null,
          parentEntity: "mission@0b1cd61d-bb36-4cf8-8f3d-9cc9b14ff054",
          references: { glyphId: "glyph" },
          rootAggregateId: "mission@0b1cd61d-bb36-4cf8-8f3d-9cc9b14ff054",
          rootAggregatePath: [
            "private",
            "notes",
            "note@032b8836-f647-4165-9ec9-fc22769f3ffa",
          ],
          status: "published",
          summaries: {
            description: "hello world",
            glyph: "bookmark",
            glyphColor: "base",
            info: "hello world",
          },
          type: "note",
          values: null,
          version: 0,
        },
      },
    }



function* extract(next) {
  const q = r
    .db("test")
    .table("mission")
    .getAll(true, { index: "recurrenceEnabled" })
    .filter((mission) => mission("meta")("status").eq("published"))
    .map((m) => {
      let t = m("private")("notes");
      let p = Object.keys(t)[0];

      return {
        note: t,
        id: m("id"),
        info: m("meta")("summaries")("info"),
       
      };
    });
  return yield q.run(con, next);
}

Thank you for the reading !

0 Answers
Related