mongodb什么时候使用
First and foremost, MongoDB is not a replacement for any traditional RDMS databases. But, considering the fact that the MongoDB structures/stores the data in the form of BSON (Binary representation of JSON) which is a self-explaining and human readable data format and the way it provides the scaling feature to the application to be developed, below are some important factors which clearly states that the developer(s) should go for the use of MongoDB for developing their applications.
首先,MongoDB不能替代任何传统的RDMS数据库。 但是,考虑到MongoDB以BSON(JSON的二进制表示形式)的形式构造/存储数据的事实(这是一种不言而喻的,人类可读的数据格式)以及它为要开发的应用程序提供缩放功能的方式,以下是一些重要因素,这些因素明确指出开发人员应使用MongoDB来开发其应用程序。
(Data Insert Consistency)
Basically, MongoDB likes to have more data insertion rate over the safety concerns of doing inserts in a transaction. Hence the write consistency is low. If there is a need for huge load of data to be written, without the worry of losing some data, then MongoDB should be preferred and really it's best suited.
基本上,MongoDB希望在事务中进行插入时比在安全方面要有更多的数据插入率。 因此,写一致性低。 如果需要写入大量数据,而又不必担心丢失一些数据,那么MongoDB应该是首选,并且确实是最合适的。
(Data Corruption Recovery)
When data recovery process needs to be faster, safe and automatic, MongoDB is preferred. In MySQL if a database (a few tables) become corrupt, you can repair them individually by deleting/updating the data. In MongoDB, you have to repair on a database level. But there is a command to do this automatically, but it reads all the data and re-writes it to a new set of files. So if your database is huge, it might take some time, and for that time your DB will be locked. But again, this is better than losing the complete dataset.
当数据恢复过程需要更快,安全和自动化时,MongoDB是首选。 在MySQL中,如果数据库(几个表)损坏了,则可以通过删除/更新数据来单独修复它们。 在MongoDB中,您必须在数据库级别进行修复。 但是有一个命令可以自动执行此操作,但是它会读取所有数据并将其重新写入一组新文件。 因此,如果您的数据库很大,则可能需要一些时间,并且在那段时间内您的数据库将被锁定。 但是同样,这比丢失完整的数据集更好。
(Load Balancing)
When data grows infinitely and proper load balancing of the same is required, MongoDB is the best solution. Because, it supports, faster replica setting options and its built in Sharding feature.
当数据无限增长并且需要适当的负载平衡时,MongoDB是最佳解决方案。 因为它支持更快的副本设置选项及其内置的分片功能。
(Avoid JOINS)
When the developers do not want to normalize their data and insist on not using of any JOINS, then they should really go for MongoDB. For Example : If there are 2 collections student and address (where a student can have more than one address). In a typical RDBMS, to fetch the addresses associated to a student from the address table, JOIN is used. But, in MongoDB, the address data can be embedded as a document in the student
地址表中获取与学生相关的地址 ,可以使用JOIN。 但是,在MongoDB中,地址数据可以作为文档嵌入到学生集合本身中。 因此,无需使用任何JOIN,就可以通过一个简单的查询获取学生和地址的所有所需详细信息。
db.address.insert([
{
_id: 'addr1',
name: 'Bangalore'
},
{
_id: 'addr2',
name: 'Delhi'
}
]);
db.student.insert([
{
_id: 's1',
name: 'Student1',
address: ['addr1']
},
{_id: 's2',
name: 'Student2',
address: ['addr1','addr2']
},
]);
(Best suited for changing schema)
It is a known fact that, whenever a table in any RDBMS is altered (like adding a new column), there is a high chance that the entire database might get locked which in turn result in a big performance degradation. Since, MongoDB is schema-less, hence adding new fields will not result in any issues.
众所周知的事实是,只要更改了任何RDBMS中的表(如添加新列),整个数据库就很有可能被锁定,从而导致性能大幅下降。 由于MongoDB是无架构的,因此添加新字段不会导致任何问题。
(Not Relational data)
When the data to be stored need not to be a relational one, then MongoDB should be selected.
如果要存储的数据不必是关系数据,则应选择MongoDB。
(Some more reasons...)
- Even though SQL databases possess very good consistency, they are bad in partitioning of the data. NoSQL database like MongoDB can be used in this scenario.
即使SQL数据库具有非常好的一致性,但它们在数据分区方面还是很糟糕的。 在这种情况下,可以使用像MongoDB这样的NoSQL数据库。 - Mapping of your application Data objects, directly into the document based storage is very easy. As the JSON like format closely resembles the Object representation in any programming language. Document matches more closely to an object than a set of relational tables of RDBMS.
将应用程序数据对象直接映射到基于文档的存储中非常容易。 由于类似JSON的格式非常类似于任何编程语言中的Object表示形式。 文档比一组RDBMS关系表更匹配对象。 - If you plan on creating a DB cluster, which might be geographically distributed to provide speeded up data queries, then MongoDB should be your choice.
如果您计划创建数据库集群,该集群可能在地理上分布以提供加速的数据查询,那么应该选择MongoDB。
翻译自: https://www.studytonight.com/mongodb/why-switch-to-mongodb
mongodb什么时候使用