【问题标题】:Couchbase modeling techniquesCouchbase 建模技术
【发布时间】:2019-06-17 07:17:44
【问题描述】:

我正在为我的团队做一些研究,试图了解 couchbase。现在,我正在研究 couchbase 中的建模实践。

我发现这篇写于 2016 年 8 月的文章谈到了couchbase modeling

这表明不是只有一个文档

key : hernandez94
{
        "username" : "hernandez94",
        "firstName" : "Jennifer",
        "middleName" : "Maria",
        "lastName" : "Hernandez",
        "addresses" : [
                 { "type" : "home", "addr1" : "1929 Crisanto Ave", "address" : "Apt 123", "addr3" : "c/o  J. Hernandez", "city" : "Mountain View", "state" : "CA", "country" : "USA", "pcode" : "94040" },
                 { "type" : "work", "addr1" : "2700 W El Camino Real", "addr2" : "Suite #123", "city" : "Mountain View", "state" : "CA", "country" : "USA", "pcode" : "94040" }
        ],
        "createdate" : “2016-08-01 15:03:40”,
        "lastlogin": "2016-08-01 17:03:40",
        "pword": "app-hashed-password",
        "loc": "IP or fqdn",
        "enabled" : true,
        "sec-questions" : [
                 { "question1" : "Security question 1 goes here", "answer" : "Answer to security question 1 goes here" },
                 { "question2" : "Security question 2 goes here", "answer" : "Answer to security question 2 goes here" },
                 { "question3" : "Security question 3 goes here", "answer" : "Answer to security question 3 goes here" }
        ],
        "doc-type" : "user"
}

您将其拆分为多个文档: 用户文档

key : hernandez94

{
    "firstName" : "Jennifer",
    "middleName" : "Maria",
    "lastName" : "Hernandez",
    "addresses" : [
        { "type" : "home", "addr1" : "1929 Crisanto Ave", "address" : "Apt 123", "addr3" : "c/o J. Hernandez", "city" : "Mountain View", "state" : "CA", "country" : "USA", "pcode" : "94040" },
        { "type" : "work", "addr1" : "2700 W El Camino Real", "addr2" : "Suite #123", "city" : "Mountain View", "state" : "CA", "country" : "USA", "pcode" : "94040" }
    ]
    "createdate" : "2016-08-01 15:03:40",
    "doc-type" : "user"
}

登录文档

key : login-info::hernandez94

{
        "lastlogin": "2016-08-01 15:03:40",
        "pword": "app-hashed-password",
        "loc": "IP or fqdn",
        "enabled" : true,
        "doc-type" : "login-info",
        "username" : "hernandez94"
}

秒问题文档

key : sec-questions::hernandez94

{
 "question1" : { "question" : "Security question 1 goes here", "answer" : "Answer to security question 1 goes here" },
    "question2" : { "question" : "Security question 2 goes here", "answer" : "Answer to security question 2 goes here" },
    "question3" : { "question" : "Security question 3 goes here", "answer" : "Answer to security question 3 goes here" },
 "doc-type" : "sec-questions",
 "username" : "hernandez94"
}

由于这是一项较新的技术,做某事的最佳方式更频繁地变化,这种策略是否仍然可行?还是 N1QL 在 couchbase 5.0 上的性能更好,从而使这种建模技术过时了?应该将我的所有数据(每个用户)放在一个文档中还是将其拆分为 1000 万 x(子文档数)?我将拥有大约 1000 万用户。

谢谢

【问题讨论】:

    标签: couchbase document-database


    【解决方案1】:

    在不进行测量或不了解您的确切使用模式的情况下,我只能提供一般性建议。

    我建议您考虑如何访问此用户文档。您是否经常只获取中心文档,还是通常将其与辅助文档结合起来并获取所有内容?如果前者占主导地位,请务必将文档分成几部分并仅获取您需要的内容。但如果后者占主导地位,请将所有数据保存在单个文档中,避免每次需要为用户获取数据时多次获取和连接的成本。

    【讨论】:

    • @MicahPearce 如果您担心获取大型文档的成本,请记住 Couchbase SDK 支持子文档操作 - 例如获取和修改文档的特定部分。
    猜你喜欢
    • 2012-09-05
    • 1970-01-01
    • 2011-04-28
    • 2019-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    相关资源
    最近更新 更多