本人刚入行手游服务端开发,目前在跟一个项目,里面主要用到mongo db来存储数据,这两天纠结于mongo存储空间的问题:使用数组格式来存储数据和使用记录类型格式来存储数据,哪一种存储更加节省空间?
记录类型格式
{
“playerId”:1234,
“username”:“bob”
“desc”:“play game”
}
数组格式:
{1234,“bob”,“play game”}
问题扩展
如果使用数组格式出库和入库会不会乱序?比如入库{1,2,3}
,读取读出来会不会成了{2,3,1}
,目前测试好像不会乱序。我想知道一些mongo底层原理,有什么好的推荐(网站,书籍,问答)?
通常你们更加倾向使用哪种格式来存储数据?为什么?
可能问题问得不是很好,望见谅。
为情所困2017-04-28 09:06:14
Tend to the first one
Don’t worry so much about storage space. The current 5KW data in the project has about 10 keys for each piece of data. The total storage space for index and data is not very large, probably no more than 100G.
The first format is more query-friendly.
Mongo itself is a document database, and the data will be stored in a bson structure (similar to json).
Array reordering will not happen.
世界只因有你2017-04-28 09:06:14
As document data, why not choose one that is more convenient and easy to use? It can also avoid the order problem you mentioned. I guess the data order will not be messed up, even if you use an array. The basis is that mongo is stored in the order of file space storagejson
来存呢。无论是解析还是装载,都比数组更方便啊。如果用json
高洛峰2017-04-28 09:06:14
Use record type format to store.
Easy to read, easy to query, and easy to count. Data is not only stored, but also easy to use.
The space occupied at the database level can be ignored, and the hard disk is the cheapest resource.
As long as the data structure you use logically is in order, then both storage and reading are in order.