首页 > 解决方案 > rethinkDB:​​获取对象中的第一个键名

问题描述

我刚从 rethinkDB 查询语言开始,不明白如何选择第一个键(名称)。在这种情况下,我将成为对象笔记。

我用 Object.keys(t)[0]; 尝试只返回我的参数,我做错了什么?

{
    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);
}

感谢您的阅读!

标签: javascriptrethinkdb

解决方案


推荐阅读