简体   繁体   English

mongodb,集合数据结构对性能的影响

[英]mongodb, Impact of collection data structure on performance

on the define the collection data structure, how to judge which structure is a good design or decision? 在定义收集数据结构时,如何判断哪个结构是好的设计或决策? This will affect the subsequent access to the database performance. 这将影响对数据库性能的后续访问。

for example: 例如:

when the one data like this: 当一个数据是这样的:

{
    _id:'a'
    index:1,   //index 1~n
    name:'john'
}

When n is large, meaning that data will be large and frequent deposited. 当n大时,意味着数据将大而频繁地存储。

the collection data structure will be to one dimensional object : 收集数据结构将是one dimensional object

{
    _id:'a'
    index:1,   
    name:'john'
}
.
.
.
{
    _id:'a'
    index:99,   
    name:'jule'
}

Or a composite two-dimensional object : composite two-dimensional object

{
    _id:'a'
    info:[
        {index:1,name:'john'},...,{index:99,name:'jule'}   
    ]
}

composite two-dimensional object can effectively reduce the number of data, however, the search method is not convenient for writing, and whether it will actually reduce the effectiveness of searching or depositing a database. composite two-dimensional object可以有效地减少数据量,但是搜索方法不便于编写,并且是否会降低搜索或存储数据库的有效性。

Or the number of data is the key to affecting the effectiveness of the database. 或数据数量是影响数据库有效性的关键。

"Better" means different things to different use cases. “更好”对不同用例意味着不同的含义。 What works in your case might not necessarily work in other use cases. 在您的情况下有效的方法不一定在其他用例中有效。

Generally, it is better to avoid large arrays, due to: 通常,由于以下原因,最好避免使用大数组:

  1. MongoDB's document size limitation (16MB). MongoDB的文档大小限制(16MB)。
  2. Indexing a large array is typically not very performant. 索引大型数组通常性能不佳。

However, this is just a general observation and not a specific rule of thumb. 但是,这只是一般性观察,而不是特定的经验法则。 If your data lends itself to an array-based representation and you're certain you'll never hit the 16MB document size, then that design may be the way to go (again, specific to your use case). 如果您的数据适合采用基于数组的表示形式,并且确定您永远不会达到16MB的文档大小,那么这种设计可能是可行的方法(同样,特定于您的用例)。

You may find these links useful to get started in schema design: 您可能会发现以下链接对于开始架构设计很有用:

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

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