【问题标题】:Nested Documents in FaunaDBFaunaDB 中的嵌套文档
【发布时间】:2021-04-07 06:32:28
【问题描述】:

我刚刚开始 Fauna 和 FQL。我们如何使用在线 shell 在另一个文档中添加嵌套文档?

这是我目前所拥有的

users: [
    {
      userID: "from google",
      userName: "from signup form",
      userEmail: "from signup form form",
      profileimgurl: "maybe from google",
      accessCode: 12345,
      role: "main or secondary. customer will automatically become main."
    },
    {
      userID: "from google",
      userName: "from signup form",
      userEmail: "from signup form form",
      profileimgurl: "maybe from google",
      accessCode: 12345,
      role: "main or secondary. customer will automatically become main."
    }
  ]

【问题讨论】:

    标签: faunadb


    【解决方案1】:

    Fauna 将数据存储在无模式 Documents 中,因此您可以在 Document 的数据中嵌入数组或其他对象。例如,从外壳:

    Create(
      Collection("users"),
      {
        data: { 
          name: "Paul",
          email: "paul@paul.com
          address: {
            country: "United States",
          },
          tags: ["pinball", "camping"]
        }
      }
    )
    

    根据您阅读和更新文档的方式,可能适合将数据保存在单独的集合中并与References保持关系。

    Create(
      Collection("public_profiles"),
      {
        data: { 
          name: "Paul",
          tags: ["pinball", "camping"]
        }
      }
    )
    
    {
      ref: Ref(Collection("public_profiles"), "307924242117165124"),
      ts: 1629918291110000,
      data: { name: "Paul", tags: ["pinball", "camping"] }
    }
    
    Update(
      Ref(Collection("users"), "307924248572638574"),
      {
        data: { 
          tags: null,
          profile: Ref(Collection("public_profiles"), "307924242117165124")
        }
      }
    )
    

    文档有一个Social Graph example,它演示了如何创建和查询关系。

    【讨论】:

      猜你喜欢
      • 2020-07-21
      • 2022-07-16
      • 2018-09-19
      • 2018-03-09
      • 2021-11-12
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多