哪个CouchDB或MongoDB适合我的需求?[英] Which of CouchDB or MongoDB suits my needs?

本文是小编为大家收集整理的关于哪个CouchDB或MongoDB适合我的需求?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

在我工作的地方,我们在轨道上使用Ruby来创建后端和前端应用程序.通常,这些应用程序与相同的MySQL数据库进行交互.它对我们的大多数数据都非常有用,但是我们有一种我想转移到NOSQL环境的情况.

我们有客户,我们的客户拥有我们所谓的"库存" - 其中一个或多个.库存可以拥有数千个项目.目前是通过两个关系数据库表完成的,inventories和inventory_items.

当两个不同的库存具有不同的参数时,问题开始:

# Inventory item from inventory 1, televisions 
{
  inventory_id: 1
  sku: 12345
  name: Samsung LCD 40 inches
  model: 582903-4
  brand: Samsung
  screen_size: 40
  type: LCD
  price: 999.95
}

# Inventory item from inventory 2, accomodation
{
  inventory_id: 2
  sku: 48cab23fa
  name: New York Hilton
  accomodation_type: hotel
  star_rating: 5
  price_per_night: 395
}

由于我们显然不能将brand或star_rating用作inventory_items>>>的列名,因此我们到目前为止我们的解决方案是使用text_a,text_b,float_a的通用列名称,int_a等,并介绍第三个表格,inventory_schemas.现在的桌子看起来像这样:

# Inventory schema for inventory 1, televisions 
{
  inventory_id: 1
  int_a: sku
  text_a: name
  text_b: model
  text_c: brand
  int_b: screen_size
  text_d: type
  float_a: price
}

# Inventory item from inventory 1, televisions 
{
  inventory_id: 1
  int_a: 12345
  text_a: Samsung LCD 40 inches
  text_b: 582903-4
  text_c: Samsung
  int_a: 40
  text_d: LCD
  float_a: 999.95
}

这效果很好...直到一点.它笨拙,不直觉,缺乏可扩展性.我们必须投入资源来设置库存模式.使用单独的表不是一个选项.

输入NOSQL.有了它,我们可以让每个项目都有自己的参数,并且仍然将它们存储在一起.从我所做的研究中,对于这种情况来说,这似乎是一个很大的替代.

具体来说,我看了Couchdb和MongoDB.两者看起来都很棒.但是,我们还需要使用其他一些零件来处理我们的库存:

  • 我们需要能够从一个(或几个)库存中选择项目.
  • 我们需要能够根据其参数过滤(例如,从库存2中获取所有类型为"酒店"的项目).
  • 我们需要能够根据参数进行分组(例如,从库存1中获得最低价格,品牌为"三星").
  • 我们需要(可能)一次检索数千个项目.
  • 我们需要能够从多个应用程序访问数据;后端(处理数据)和前端(显示数据).
  • 不需要快速散装插入.

基于结构和要求,couchdb或MongoDB适合我们?如果是这样,哪一个最适合?

感谢您的阅读,并提前感谢您的答案.

编辑:我喜欢CouchDB的原因之一是,在Frontend应用程序中,我们可以直接从服务器上通过JavaScript从服务器加载后直接从服务器请求数据,并显示结果而无需使用任何后端代码.这将导致更好的页面负载和减少服务器应变,因为将完成数据的获取/处理客户端.

推荐答案

我在MongoDB上工作,所以您应该用一粒盐来服用它,但这看起来非常适合Mongo.

  • 我们需要能够从一个(或几个)库存中选择项目.

很容易在任何字段上进行临时查询.

  • 我们需要能够根据其参数过滤(例如,从库存2中获取所有类型为"酒店"的项目).

查询的是:{"inventory_id" : 2, "type" : "hotel"}.

  • 我们需要能够根据参数进行分组(例如,从库存1中获得最低价格,品牌为"三星").

再次,超级简单:db.items.find({"brand" : "Samsung"}).sort({"price" : 1})

  • 我们需要(可能)一次检索数千个项目.

没问题.

  • 不需要快速散装插入.

mongoDB的散装插入速度比couchdb更快.

另外,还有一个or rest接口:

您可能想阅读 http://chemeo.com/doc/technology MongoDB的任意属性搜索问题

本文地址:https://www.itbaoku.cn/post/597474.html

问题描述

Where I work, we use Ruby on Rails to create both backend and frontend applications. Usually, these applications interact with the same MySQL database. It works great for a majority of our data, but we have one situation which I would like to move to a NoSQL environment.

We have clients, and our clients have what we call "inventories"--one or more of them. An inventory can have many thousands of items. This is currently done through two relational database tables, inventories and inventory_items.

The problems start when two different inventories have different parameters:

# Inventory item from inventory 1, televisions 
{
  inventory_id: 1
  sku: 12345
  name: Samsung LCD 40 inches
  model: 582903-4
  brand: Samsung
  screen_size: 40
  type: LCD
  price: 999.95
}

# Inventory item from inventory 2, accomodation
{
  inventory_id: 2
  sku: 48cab23fa
  name: New York Hilton
  accomodation_type: hotel
  star_rating: 5
  price_per_night: 395
}

Since we obviously can't use brand or star_rating as the column name in inventory_items, our solution so far has been to use generic column names such as text_a, text_b, float_a, int_a, etc, and introduce a third table, inventory_schemas. The tables now look like this:

# Inventory schema for inventory 1, televisions 
{
  inventory_id: 1
  int_a: sku
  text_a: name
  text_b: model
  text_c: brand
  int_b: screen_size
  text_d: type
  float_a: price
}

# Inventory item from inventory 1, televisions 
{
  inventory_id: 1
  int_a: 12345
  text_a: Samsung LCD 40 inches
  text_b: 582903-4
  text_c: Samsung
  int_a: 40
  text_d: LCD
  float_a: 999.95
}

This has worked well... up to a point. It's clunky, it's unintuitive and it lacks scalability. We have to devote resources to set up inventory schemas. Using separate tables is not an option.

Enter NoSQL. With it, we could let each and every item have their own parameters and still store them together. From the research I've done, it certainly seems like a great alterative for this situation.

Specifically, I've looked at CouchDB and MongoDB. Both look great. However, there are a few other bits and pieces we need to be able to do with our inventory:

  • We need to be able to select items from only one (or several) inventories.
  • We need to be able to filter items based on its parameters (eg. get all items from inventory 2 where type is 'hotel').
  • We need to be able to group items based on parameters (eg. get the lowest price from items in inventory 1 where brand is 'Samsung').
  • We need to (potentially) be able to retrieve thousands of items at a time.
  • We need to be able to access the data from multiple applications; both backend (to process data) and frontend (to display data).
  • Rapid bulk insertion is desired, though not required.

Based on the structure, and the requirements, are either CouchDB or MongoDB suitable for us? If so, which one will be the best fit?

Thanks for reading, and thanks in advance for answers.

EDIT: One of the reasons I like CouchDB is that it would be possible for us in the frontend application to request data via JavaScript directly from the server after page load, and display the results without having to use any backend code whatsoever. This would lead to better page load and less server strain, as the fetching/processing of the data would be done client-side.

推荐答案

I work on MongoDB, so you should take this with a grain of salt, but this looks like a great fit for Mongo.

  • We need to be able to select items from only one (or several) inventories.

It's easy to ad hoc queries on any fields.

  • We need to be able to filter items based on its parameters (eg. get all items from inventory 2 where type is 'hotel').

The query for this would be: {"inventory_id" : 2, "type" : "hotel"}.

  • We need to be able to group items based on parameters (eg. get the lowest price from items in inventory 1 where brand is 'Samsung').

Again, super easy: db.items.find({"brand" : "Samsung"}).sort({"price" : 1})

  • We need to (potentially) be able to retrieve thousands of items at a time.

No problem.

  • Rapid bulk insertion is desired, though not required.

MongoDB has much faster bulk inserts than CouchDB.

Also, there's a REST interface for MongoDB: http://github.com/kchodorow/sleepy.mongoose

You might want to read http://chemeo.com/doc/technology, who dealt with the arbitrary property search problem with MongoDB.