Discard relational database PHP programmers should know five things about MongoDB

Source: Internet
Author: User
Keywords nbsp can fit traditional

"51CTO exclusive feature" 2010 should be remembered, because the SQL will die in the year. This year's relational database is on the go, and this year developers find that they don't need long, laborious construction columns or tables to store data.

2010 will be the starting year for a document database. Although the momentum has been going on for years, now is the age when more and more extensive document databases appear. From cloud-based Amazon to Google, a number of open-source tools, along with the birth of Couchdb and MongoDB.

So what is MongoDB? Here are five things that PHP developers should know.

1.MongoDB is a separate server

2.MongoDB is document based, not table based

Less schema in 3.MongoDB

4. You don't need to learn another language.

5.MongoDB has good PHP support

1.MongoDB is a separate server

Like MySQL and PostgreSQL, MongoDB will listen for access links. It provides tools that include inquiries, creation, updates, and deletions. In theory, you will work in the same way as MySQL and PostgreSQL: link, process, and then close the link.

2. Say goodbye to rows and tables welcome documents and Collectors

Instead of the tables and rows where the data is stored, MongoDB stores the data in the document. If we have an "article" with a title, it has multiple authors, a theme and a label. All this looks like the following:

<?php Array (' title ' => ' Hello World ', ' authors ' => array (' John ', ' Sally ', ' Jim '), ' body ' => ' Hello World ', '  Tags ' => array (' Tag1 ', ' tag2 ', ' tag3 ')); ?>

The most critical of the above example is that record--this document--yes, it does. It's like a document that supports a compound form of values stored in the same area. No more need to be structured, no need to differentiate data by table. Therefore, the table no longer exists.

3.MongoDB contains fewer schemas

MongoDB does not have a schema language. If you want to create a new type of document, you don't need to tell the database anything. Even if you put the new data in the database.

In the 2nd, I simulate a document. Now I want to define an article type for all areas, all I need to do is write this data into the database. What if I decide to postpone writing? I just need to pull out this part of the data, and then add the Date field, and finally save the line.

What about data types? The simple answer is that MongoDB uses a compelling system, like JavaScript or PHP. Thus, the database is very good at weakening the role of the type.

There are some vulnerabilities (large amounts of data require some explicit definition), but in most cases you write your MongoDB code as if you were programming on PHP.

4. You don't need to learn another language.

Recall the other database abstraction layers you've written. Remember all the ORM layers you've used. Then you can abandon them now, and you can't use them on MongoDB.

MongoDB (PHP driver containing it) does not need to ask the language. In most cases, you just need to simply give a pointer to specify what you need and then return to a document pointing to it.

If you run some higher-order functions (such as map-reduce), you can add them to the MongoDB with JavaScript applications and run them in the JavaScript internal engine.

5.PHP and MongoDB are natural couples?

PHP already has good support for MongoDB. The MONGO driver can be added to PHP as a pecl add-in, which means installing MONGO as if it were running pecl.

See here, you can start to write MONGO API. More broadly, it's lined up with PDO. It's not simply extinction, but it's definitely different from the database we developed before.

The API documentation will include a guide and many examples so that you can lift yourself in a short time. The following will be helpful tips for you.

MongoDB is developing very fast.

The development time is very short, there is not too much mode to manage, few (if any) data maps.

Because there is no new query language to learn, code adjustment is very small. After all, you don't need another ORM, and the packet is very light.

Your code is a promise for the future and it can be easier to add more fields to your objects, even more complex areas. So your code can easily adapt to changing requirements.

Extended Reading

MongoDB Logo

MONGO is a high-performance, open source, modeless document database that can be used to replace traditional relational databases or key/value storage in many scenarios. MONGO uses C + + development to provide the following features:

Collection-oriented storage: data that is appropriate for storing objects and JSON forms.

Dynamic query: MONGO supports rich query expressions. Query directives use JSON-form tags to easily query objects and arrays embedded in the document.

Full index support: Includes document inline objects and arrays. The MONGO query optimizer analyzes query expressions and generates an efficient query plan.

Query monitoring: MONGO contains a monitoring tool for analyzing the performance of database operations.

Replication and automatic failover: The MONGO database supports data replication between servers, supporting master-from-mode and server replication. The primary goal of replication is to provide redundancy and automatic failover.

Efficient traditional storage: supports binary data and large objects such as photos or pictures.

Automatic fragmentation to support cloud-level scalability (in the early alpha phase): Automatic fragmentation supports a level of database clustering that can dynamically add additional machines.

The main goal of MongoDB is to set up a bridge between key/value storage (high performance and high scalability) and traditional RDBMS systems (rich functionality), combining the advantages of both. According to the official website description, MONGO is suitable for the following scenarios:

Site data: MONGO is ideal for real-time inserts, updates, and queries, as well as the replication and high scalability required for real-time data storage on the Web site.

Caching: Because of its high performance, MONGO is also suitable as a caching layer for the information infrastructure. After the system restarts, the persistent cache layer built by MONGO can avoid overloading the underlying data source.

Large size, low value data: It may be expensive to store some data using a traditional relational database, before which programmers often choose traditional files for storage.

Highly scalable scenario: MONGO is ideal for databases composed of dozens of or hundreds of servers. The MONGO roadmap already contains built-in support for the MapReduce engine.

Storage for objects and JSON data: MONGO's Bson data format is ideal for storing and querying in a documented format.

Naturally, the use of MongoDB can also have some limitations, such as it does not fit:

Highly transactional system: such as a bank or accounting system. Traditional relational databases are now more suitable for applications that require a large number of atomic complex transactions.

Traditional business intelligence applications: The BI database for a particular problem is a highly optimized query. For such applications, the Data warehouse may be a more appropriate choice.

Problems requiring SQL

MongoDB supports operating systems such as OS X, Linux, and Windows and provides drivers for Python,php,ruby,java and C + + languages, as well as drivers for Erlang and. NET platforms in the community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.