CouchDB 中地址簿的最佳文档格式

发布于 2024-08-30 12:51:51 字数 874 浏览 5 评论 0原文

我真的很努力,很努力,但我无法理解 couchdb :( 我必须记录几个人的联系方式,我应该将每个联系人放在一个文档中吗?

"1th documet"
{
 "names" : [
  Jake", "Lock"
 ]

 "numbers" : [
  "Jake's number", "Lock's number"
 ]
}

Future records:

"1th documet"
{
 "names" : [
  Jake", "Lock", "Kate", "Jin", ...
 ]

 "numbers" : [
  "Jake's number", "Lock's number", "Kate's number", "Jin's number", ...
 ]
}

还是放在不同的文档中?

"1th document"
{
 "name" : "Jake"

 "number" : "Jake's number"
}

"2th document"
{
 "name" : "Lock"

 "number" : "Lock's number"
}

Future records:

"1th document"
{
 "name" : "Jake"

 "number" : "Jake's number"
}

"2th document"
{
 "name" : "Lock"

 "number" : "Lock's number"
}

"3th document"
{
 "name" : "Kate"

 "number" : "Kate's number"
}

"4th document"
{
 "name" : "Jin"

 "number" : "Jin's number"
}

...

我很困惑,有人可以帮助我吗?

谢谢。

I really tried, tried so hard but i cant understand couchdb :( I must record the contact of several people, should i put every contact in a single document ?

"1th documet"
{
 "names" : [
  Jake", "Lock"
 ]

 "numbers" : [
  "Jake's number", "Lock's number"
 ]
}

Future records:

"1th documet"
{
 "names" : [
  Jake", "Lock", "Kate", "Jin", ...
 ]

 "numbers" : [
  "Jake's number", "Lock's number", "Kate's number", "Jin's number", ...
 ]
}

Or in different documents ?

"1th document"
{
 "name" : "Jake"

 "number" : "Jake's number"
}

"2th document"
{
 "name" : "Lock"

 "number" : "Lock's number"
}

Future records:

"1th document"
{
 "name" : "Jake"

 "number" : "Jake's number"
}

"2th document"
{
 "name" : "Lock"

 "number" : "Lock's number"
}

"3th document"
{
 "name" : "Kate"

 "number" : "Kate's number"
}

"4th document"
{
 "name" : "Jin"

 "number" : "Jin's number"
}

...

I confused, can somebody help me ?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

彡翼 2024-09-06 12:51:51

我假设您正在存储这些联系人以形成某种地址簿样式的应用程序。根据这个假设,我想说你的第二个例子正是你想要做的。在我看来,每个“联系人”都是一个文档。该联系人的所有属性都包含在文档中。

{
    name: "John Smith",
    number: "+44 1234 567890"
}

更进一步来说,将来您可能决定希望为每个人存储多个号码,也许是不同类型的号码。我会将这些全部嵌入到特定联系人的文档中:

{
    name: "John Smith",
    numbers: [
        { number: "+44 1234 567890", type: "home" },
        { number: "+44 7798 987654", type: "mobile" },
        { number: "+44 1234 987123", type: "work" }
    ]
}

我发现设计用于文档数据库的模型的一个好方法是考虑您希望独立使用哪些项目。对于那些本身有意义的内容,他们可能应该进入自己的文档。对于那些只有在“容器”对象的上下文中查看才有意义的对象,请将它们嵌入其中。

我希望这对你有帮助。

I assume you are storing these contacts to form some kind of address-book style application. Going with this assumption, I would say your second example is exactly what you want to be doing. The way I look at it, each "contact" is a single document. All the attributes for this contact belong within the document.

{
    name: "John Smith",
    number: "+44 1234 567890"
}

To take this a bit further, in the future you might decide you wish to store multiple numbers per person, perhaps of different types. I would embed these all inside the document for the particular contact:

{
    name: "John Smith",
    numbers: [
        { number: "+44 1234 567890", type: "home" },
        { number: "+44 7798 987654", type: "mobile" },
        { number: "+44 1234 987123", type: "work" }
    ]
}

I find a good way to approach designing a model for use in a document database is to consider what items you will wish to use independently. For those which make sense on their own, they should probably go inside their own document. For those which only make sense when viewed in the context of their "container" object, embed them within it.

I hope this helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文