代码之家  ›  专栏  ›  技术社区  ›  Micah Pearce

CouchBase建模技术

  •  2
  • Micah Pearce  · 技术社区  · 6 年前

    我正在为我的团队做一些研究,试图了解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"
    }
    

    SEC问题文件

    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万用户。

    谢谢

    1 回复  |  直到 6 年前
        1
  •  4
  •   Johan Larson    6 年前

    如果不进行测量,或者不知道您的确切使用模式,我只能给出一般性的建议。

    我建议您考虑如何访问此用户文档。您经常只获取中心文档,还是通常将其与附属文档合并并获取所有内容?如果前者占主导地位,那么一定要将文档拆分为多个部分,只获取您需要的内容。但是,如果后者占主导地位,那么将所有数据保存在一个文档中,避免每次需要为用户获取数据时多次获取和联接的成本。

    推荐文章