As a PHP programmer, you should know five things about MongoDB _php instance

Source: Internet
Author: User
Tags arrays documentation failover mongodb php and postgresql
2010 should be remembered, because the SQL will die in this 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 based on documentation, not on tables;
3. Fewer schemas in the 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. The tools it provides 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:
Copy Code code as follows:

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. As a result, 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, then add the Date field, and then save the line.
So what about data types? The simple answer is that MongoDB uses a mandatory 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 the 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 that points to you.
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 a 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've 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, the adjustment of the code 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 changes in demand.
Extended Reading
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:
set-oriented storage:Suitable for storing data in the form of objects and JSON.
Dynamic Query:MONGO supports rich query expressions. Query directives use JSON-form tags to easily query objects and arrays that are embedded in the document.
Full index support:Includes document inline objects and arrays. The MONGO query optimizer analyzes the query expression 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 and traditional storage mode:Supports binary data and large objects (such as photographs or pictures).
automatic fragmentation to support cloud-level scalability (in the early alpha phase):The automatic fragmentation feature 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:
website data:MONGO is ideal for real-time inserts, updates, and queries, as well as the replication and scalability required for real-time data storage on a 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, and before that, programmers often choose traditional files for storage.
High-scalability scenarios:MONGO is ideal for databases consisting 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 systems:such as banking or accounting systems. 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 specific problem is a highly optimized way of querying. For this type of application, the data warehouse may be a more appropriate choice.
A problem with SQL is required.
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.