MongoDB表设计和查询性能 [英] MongoDB Table Design and Query Performance

查看:311
本文介绍了MongoDB表设计和查询性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是MongoDB的新手。创建新表时,我想到了一个与如何设计它和性能有关的问题。我的表结构是这样的:

I'm new to MongoDB. When creating a new table a question came to my mind related to how to design it and performance. My table structure looks this way:

{
    "name" : string,
    "data" : { "data1" : "xxx", "data2" : "yyy", "data3" : "zzz", .... }           
}

数据字段可以增长,直到达到100.000个元素( data100.000: aaaXXX)为止。但是,此表中的行数将受到控制(介于500和1000之间)。

The "data" field could grow until it reaches an amount of 100.000 elements ( "data100.000" : "aaaXXX"). However the number of rows in this table would be under control (between 500 and 1000).

该表在我的应用程序中将被访问很多次,我想最大化任何查询的性能。我会做这样的查询(我将在Java中举一个例子):

This table will be accessed many times in my application and I'd like to maximize the performance of any queries. I would do queries like this one (I'll put an example in java):

new Query().addCriteria(Criteria.where("name").is(name).and("data.data3").is("zzz"));

我不知道当 dataX ...元素的数量增加时,它是否会变慢成长。

I don't know if this would get slower when the amount of "dataX"... elements grows.

所以问题是:这种设计正确吗?我应该更改一些东西吗?

我很高兴阅读您的建议,非常感谢

I'll be pleased to read your advice, many thanks in advance

推荐答案

文档可以像带有列的表一样查看,但是您必须小心。它具有其他使用特性。文件大小最大。 16 MB。而且,您必须记住,文档是由mongo保留在内存中的。

A document could be viewed like a table with columns, but you have to be carefull. It has other usage characteristics. The document size can be max. 16 MB. And you have to keep in mind that the documents are hold in memory by mongo.

使用您的查询将返回整个文档。问问自己,您是否需要所有条目,或者
您是否必须自己使用一个条目?

With your query the whole document will be returned. Ask yourself do you need all entries or will you have to use a single entry on his own?

  • Using MongoDB for eCommerce
  • MongoDB Schema Design
  • MongoDB and eCommerce
  • MongoDB Transactions

这应该是一个好的开始。

This should be a good start.

这篇关于MongoDB表设计和查询性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆