What are the advantages of using a schema-free database like MongoDB compared to a relational database?

前端 未结 9 1806
别那么骄傲
别那么骄傲 2020-12-22 16:02

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 la

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-22 17:02

    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!

提交回复
热议问题