Couchbase建模技术
我正在为我的团队做一些研究,试图了解couchbase。现在,我正在研究couchbase中的建模实践 我发现这篇写在2016年8月的文章谈到了 它建议,与其只有一份文件Couchbase建模技术,couchbase,document-database,Couchbase,Document Database,我正在为我的团队做一些研究,试图了解couchbase。现在,我正在研究couchbase中的建模实践 我发现这篇写在2016年8月的文章谈到了 它建议,与其只有一份文件 key : hernandez94 { "username" : "hernandez94", "firstName" : "Jennifer", "middleName" : "Maria", "lastName" : "Hernandez",
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 : 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"
}
既然这是一项更新的技术,做某事的最佳方式会更频繁地发生变化,那么这种策略仍然可行吗?还是couchbase 5.0上N1QL的性能好得多,使得这种建模技术过时了?我应该将每个用户的所有数据放在一个文档中,还是将其拆分为1000万x个子文档?我将拥有大约1000万用户
谢谢没有测量,也不知道您的确切使用模式,我只能给出一般性的建议
我建议你考虑一下你将如何访问这个用户文档。您通常只获取中心文档,还是将其与辅助文档合并并获取所有内容?如果前者占主导地位,那么一定要把文档分成几部分,只取你需要的东西。但如果后者占主导地位,则将所有数据保存在单个文档中,避免每次需要为用户获取数据时多次获取和连接的成本 @MicahPearce如果您担心获取大型文档的成本,请记住Couchbase SDK支持子文档操作,例如获取和修改文档的特定部分。
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"
}