简体   繁体   English

在MongoDB中存储多维数据

[英]Storing multidimensional data in MongoDB

I am attempting to convert a large MySQL database of product information (dimensions, specifications, etc) to MongoDB for flexibility and to move away from the restriction of a column based table. 我正在尝试将产品信息(尺寸,规格等)的大型MySQL数据库转换为MongoDB,以提高灵活性,并摆脱基于列的表的限制。 I like the freedom of being able to add a new key-value, without making an update to table structure. 我喜欢无需添加表键即可添加新键值的自由。

An example of my data is here: http://textuploader.com/9nwo . 我的数据示例在这里: http : //textuploader.com/9nwo I envisioned my collection being "Products", with a nested collection for each product type (ex. Hand Chain Hoists), and a nested collected manufacturer (ex. Coffing & Harrington). 我设想我的收藏是“产品”,每种产品类型都有一个嵌套的收藏(例如,手拉式葫芦),一个嵌套的制造商(例如,Coffing和Harrington)。 Basically one large multidimensional array. 基本上是一个大型多维数组。 I am learning that nested collections are not allowed in MongoDB, so I'm at a dead end. 我了解到MongoDB中不允许使用嵌套集合,所以我处于死胡同。

How would you store this kind of dataset? 您将如何存储这种数据集? Is NoSQL the right choice for this? NoSQL是否是正确的选择?

If the nested structure is not necessary, you can "flatten" your data by having each document in the collection be a specific product and each product can have manufacturer product type as fields. 如果不需要嵌套结构,则可以通过使集合中的每个文档为特定产品来“拼合”数据,并且每个产品都可以将制造商产品类型作为字段。 You can index these fields so you can still query them quickly without a nested structure. 您可以为这些字段建立索引,因此仍然可以在没有嵌套结构的情况下快速查询它们。

If you need to preserve the hierarchy, mongodb actually has a tutorial on designing a product hierarchy model here: http://docs.mongodb.org/ecosystem/use-cases/category-hierarchy/ . 如果您需要保留层次结构,则mongodb实际上在此处提供了有关设计产品层次结构模型的教程: http : //docs.mongodb.org/ecosystem/use-cases/category-hierarchy/ Essentially, each product has an ancestors array. 本质上,每个产品都有一个祖先阵列。 It is a bit trickier keeping the hierarchy up to date on inserts and updates 使插入和更新的层次结构保持最新状态有点棘手

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

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