首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FaunaDB中的嵌套文档

FaunaDB中的嵌套文档
EN

Stack Overflow用户
提问于 2020-12-31 03:06:19
回答 1查看 30关注 0票数 0

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

这是我到目前为止所拥有的

代码语言:javascript
复制
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."
    }
  ]
EN

回答 1

Stack Overflow用户

发布于 2021-08-25 20:44:33

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

代码语言:javascript
复制
Create(
  Collection("users"),
  {
    data: { 
      name: "Paul",
      email: "paul@paul.com
      address: {
        country: "United States",
      },
      tags: ["pinball", "camping"]
    }
  }
)

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

代码语言:javascript
复制
Create(
  Collection("public_profiles"),
  {
    data: { 
      name: "Paul",
      tags: ["pinball", "camping"]
    }
  }
)

{
  ref: Ref(Collection("public_profiles"), "307924242117165124"),
  ts: 1629918291110000,
  data: { name: "Paul", tags: ["pinball", "camping"] }
}
代码语言:javascript
复制
Update(
  Ref(Collection("users"), "307924248572638574"),
  {
    data: { 
      tags: null,
      profile: Ref(Collection("public_profiles"), "307924242117165124")
    }
  }
)

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65512302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档