简体   繁体   English

PouchDB结构

[英]PouchDB structure

i am new with nosql concept, so when i start to learn PouchDB , i found this conversion chart. 我是nosql概念的新手,所以当我开始学习PouchDB时 ,我找到了这个转换图表。 My confusion is, how PouchDB handle if lets say i have multiple table, does it mean that i need to create multiple databases? 我的困惑是, PouchDB如何处理,如果我说我有多个表,这是否意味着我需要创建多个数据库? Because from my understanding in pouchdb a database can store a lot of documents, but a document mean a row in sql or am i misunderstood? 因为从我对pouchdb的理解,一个数据库可以存储很多文件,但是一个文件在sql中意味着一行还是我被误解了?

在此输入图像描述

The answer to this question seems to be surprisingly under-documented. 这个问题的答案似乎令人惊讶地记录不足。 While @llabball clearly gave a decent answer, I don't think that views are always the way to go. 虽然@llabball明显给出了一个不错的答案,但我认为这些观点总是不可能的。

As you can read here in the section When not to use map/reduce , Nolan explains that for simpler applications, the key is to abuse _ids , and leverage the power of allDocs() . 正如你可以看到这里的部分。当不使用的map / reduce,诺兰解释说,简单的应用,关键是滥用 _ids ,并充分利用的动力allDocs()

In other words, if you had two separate types (say artists, and albums), then you could prefix the id of each type to obtain an easily searchable data set. 换句话说,如果你有两种不同的类型(比如艺术家和专辑),那么你可以在每种类型的id前面加上一个易于搜索的数据集。 For example _id: 'artist_name' & _id: 'album_title' , would allow you to easily retrieve artists in name order. 例如_id: 'artist_name'_id: 'album_title' ,可以让您轻松按名称顺序检索艺术家。

Laying out the data this way will result in better performance due to not requiring extra indexes, and less code. 以这种方式布置数据将导致更好的性能,因为不需要额外的索引和更少的代码。 Clearly however, if your data requirements are more complex, then views are the way to go. 但是,显然,如果您的数据要求更复杂,那么视图就是可行的方法。

... does it mean that i need to create multiple databases? ......这是否意味着我需要创建多个数据库?

No. 没有。

... a document mean a row in sql or am i misunderstood? ...一个文件在sql中意味着一行还是我被误解了?

That's right. 那就对了。 The SQL table defines column header (name and type) - that are the JSON property names of the doc. SQL表定义列标题(名称和类型) - 它们是doc的JSON属性名称。

So, all docs (rows) with the same properties (a so called "schema") are the equivalent of your SQL table. 因此, 具有相同属性的所有文档(行)(所谓的“模式”)等同于SQL表。 You can have as much different schemata in one database as you want (visit json-schema.org for some inspiration). 您可以在一个数据库中拥有尽可能多的不同架构(访问json-schema.org获取一些灵感)。

How to request them separately? 如何单独申请? Create CouchDB views! 创建CouchDB视图! You can get all/some "rows" of your tabular data (docs with the same schema) with one request as you know it from SQL. 您可以使用SQL中的一个请求获取表格数据的所有/某些“行”(具有相同模式的文档)。

To write such views easily the property type is very common for CouchDB docs. 要轻松编写此类视图,属性type对于CouchDB文档非常常见。 Your known name from a SQL table can be your type like doc.type: "animal" SQL表中的已知名称可以是您的类型,如doc.type: "animal"

Your view names will be maybe animalByName or animalByWeight . 您的视图名称可能是animalByNameanimalByWeight Depends on your needs. 取决于您的需求。

Sometimes multiple-databases plan is a good option, like a database per user or even a database per user-feature. 有时,多数据库计划是一个不错的选择,例如每个用户的数据库,甚至是每个用户功能的数据库。 Take a look at this conversation on CouchDB mailing list. 在CouchDB邮件列表上查看此对话

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM