与关系型数据库相比,使用MongoDB这样的无模式数据库有什么优势?[英] What are the advantages of using a schema-free database like MongoDB compared to a relational database?

本文是小编为大家收集整理的关于与关系型数据库相比,使用MongoDB这样的无模式数据库有什么优势?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我习惯使用MySQL或PostgreSQL等关系数据库,并与Symfony,Ror或Django等MVC框架结合使用,我认为它很棒.

但是最近我听说过很多关于MongoDB的数据库,或者引用官方定义

可扩展的高性能,打开 来源,无模式,面向文档 数据库.

我真的有兴趣处于边缘状态,并想了解我为下一个项目提供的所有选项,并选择最好的技术.

在哪些情况下,使用MongoDB(或类似数据库)比使用"经典"关系数据库更好? 一般而言,MongoDB与MySQL的优势是什么? 或至少,为什么如此不同?

如果您有文档和/或示例的指针,那也将有很大的帮助.

推荐答案

这是构建Web应用程序的MongoDB的一些优点:

  1. 基于文档的数据模型.基本的存储单元类似于JSON,Python词典,Ruby Hashes等.这是一种能够保存数组和其他文档的丰富数据结构.这意味着您通常可以在单个实体中代表一个需要几个表才能正确表示关系DB中的构造.如果您的数据不变,这特别有用.
  2. 深度查询能力. MongoDB使用基于文档的查询语言支持文档的动态查询,该查询语言几乎与SQL一样强大.
  3. 没有模式迁移.由于MongoDB不含模式,因此您的代码定义了您的模式.
  4. 通往水平可伸缩性的清晰路径.

您需要阅读更多有关它的信息,并使用它来获得更好的主意.这是一个在线演示:

http://try.mongodb.org/

其他推荐答案

有许多优点.

例如,您的数据库架构将更可扩展,您不必担心迁移,编写代码将更加愉快...例如,这是我的模型代码之一:

class Setting
  include MongoMapper::Document

  key :news_search, String, :required => true
  key :is_availaible_for_iphone, :required => true, :default => false

  belongs_to :movie
end

添加键只是添加一行代码!

从长远来看,还有其他优点,例如更好的可以宽白和速度.

... ,但请记住,非关系数据库不是 比关系更好.如果您的数据库具有很大的关系和正常化,则使用MongoDB之类的东西可能没有意义.这一切都是为了找到合适的工具.

要阅读更多内容,我建议您查看" 为什么我认为mongo是数据库的frails to frameworks "或在MongoDB网站上此帖子.为了兴奋,如果您会说法语,请看一下从头开始设置mongodb.

编辑:我几乎忘了告诉您 这个铁路cast a href =" https://stackoverflow.com/users/148722/ryanb"> ryan .这很有趣,您想立即开始!

其他推荐答案

无模式的优点是您可以倾倒任何负载,没有人会抱怨它,或者说这是错误的.

这也意味着您在其中倾倒的任何东西都完全没有意义.

有些人会标记出严重的劣势,其他有些不会.

关系数据库具有良好的模式,这是因为它具有一组良好的扩展谓词,这使我们能够将含义附加到数据库中记录的内容,这是这样的事实.这也是我们这样做的必要先决条件.

没有完善的架构,没有扩展谓词,并且没有扩展的prepication,用户无法从塞满的东西中发挥任何意义.

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

问题描述

I'm used to using relational databases like MySQL or PostgreSQL, and combined with MVC frameworks such as Symfony, RoR or Django, and I think it works great.

But lately I've heard a lot about MongoDB which is a non-relational database, or, to quote the official definition,

a scalable, high-performance, open source, schema-free, document-oriented database.

I'm really interested in being on edge and want to be aware of all the options I'll have for a next project and choose the best technologies out there.

In which cases using MongoDB (or similar databases) is better than using a "classic" relational databases? And what are the advantages of MongoDB vs MySQL in general? Or at least, why is it so different?

If you have pointers to documentation and/or examples, it would be of great help too.

推荐答案

Here are some of the advantages of MongoDB for building web applications:

  1. A document-based data model. The basic unit of storage is analogous to JSON, Python dictionaries, Ruby hashes, etc. This is a rich data structure capable of holding arrays and other documents. This means you can often represent in a single entity a construct that would require several tables to properly represent in a relational db. This is especially useful if your data is immutable.
  2. Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that's nearly as powerful as SQL.
  3. No schema migrations. Since MongoDB is schema-free, your code defines your schema.
  4. A clear path to horizontal scalability.

You'll need to read more about it and play with it to get a better idea. Here's an online demo:

http://try.mongodb.org/

其他推荐答案

There are numerous advantages.

For instance your database schema will be more scalable, you won't have to worry about migrations, the code will be more pleasant to write... For instance here's one of my model's code :

class Setting
  include MongoMapper::Document

  key :news_search, String, :required => true
  key :is_availaible_for_iphone, :required => true, :default => false

  belongs_to :movie
end

Adding a key is just adding a line of code !

There are also other advantages that will appear in the long run, like a better scallability and speed.

... But keep in mind that a non-relational database is not better than a relational one. If your database has a lot of relations and normalization, it might make little sense to use something like MongoDB. It's all about finding the right tool for the job.

For more things to read I'd recommend taking a look at "Why I think Mongo is to Databases what Rails was to Frameworks" or this post on the mongodb website. To get excited and if you speak french, take a look at this article explaining how to set up MongoDB from scratch.

Edit: I almost forgot to tell you about this railscast by Ryan. It's very interesting and makes you want to start right away!

其他推荐答案

The advantage of schema-free is that you can dump whatever your load is in it, and no one will ever have any ground for complaining about it, or for saying that it was wrong.

It also means that whatever you dump in it, remains totally void of meaning after you have done so.

Some would label that a gross disadvantage, some others won't.

The fact that a relational database has a well-established schema, is a consequence of the fact that it has a well-established set of extensional predicates, which are what allows us to attach meaning to what is recorded in the database, and which are also a necessary prerequisite for us to do so.

Without a well-established schema, no extensional predicates, and without extensional precicates, no way for the user to make any meaning out of what was stuffed in it.