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

前端 未结 9 1715
别那么骄傲
别那么骄傲 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 16:57

    My experience with Postgres and Mongo after working with both the databases in my projects .

    Postgres(RDBMS)

    Postgres is recommended if your future applications have a complicated schema that needs lots of joins or all the data have relations or if we have heavy writing. Postgres is open source, faster, ACID compliant and uses less memory on disk, and is all around good performant for JSON storage also and includes full serializability of transactions with 3 levels of transaction isolation.

    The biggest advantage of staying with Postgres is that we have best of both worlds. We can store data into JSONB with constraints, consistency and speed. On the other hand, we can use all SQL features for other types of data. The underlying engine is very stable and copes well with a good range of data volumes. It also runs on your choice of hardware and operating system. Postgres providing NoSQL capabilities along with full transaction support, storing JSON documents with constraints on the fields data.

    General Constraints for Postgres

    Scaling Postgres Horizontally is significantly harder, but doable.

    Fast read operations cannot be fully achieved with Postgres.

    NO SQL Data Bases

    Mongo DB (Wired Tiger)

    MongoDB may beat Postgres in dimension of “horizontal scale”. Storing JSON is what Mongo is optimized to do. Mongo stores its data in a binary format called BSONb which is (roughly) just a binary representation of a superset of JSON. MongoDB stores objects exactly as they were designed. According to MongoDB, for write-intensive applications, Mongo says the new engine(Wired Tiger) gives users an up to 10x increase in write performance(I should try this), with 80 percent reduction in storage utilization, helping to lower costs of storage, achieve greater utilization of hardware.

    General Constraints of MongoDb

    The usage of a schema less storage engine leads to the problem of implicit schemas. These schemas aren’t defined by our storage engine but instead are defined based on application behavior and expectations.

    Stand-alone NoSQL technologies do not meet ACID standards because they sacrifice critical data protections in favor of high throughput performance for unstructured applications. It’s not hard to apply ACID on NoSQL databases but it would make database slow and inflexible up to some extent. “Most of the NoSQL limitations were optimized in the newer versions and releases which have overcome its previous limitations up to a great extent”.

    0 讨论(0)
  • 2020-12-22 16:59

    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.

    0 讨论(0)
  • 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!

    0 讨论(0)
提交回复
热议问题