Five things you should know about MongoDB as a PHP programmer _php Tutorial

Source: Internet
Author: User
Tags failover
2010 should be remembered, because SQL will die this year. This year the relational database is dying, and this year developers find that they don't need a long hard time constructing columns or tables to hold data.
2010 will be the starting year for the document database. Although this momentum has been going on for many years, it is now the era of more and more extensive document-based databases. From cloud-based Amazon to Google, lots of open source tools, and the COUCHDB and MongoDB that comes with it.
So what is MongoDB? Here are five things that PHP developers should be aware of:
1. MongoDB is a separate server;
2. MongoDB is document-based, not table-based;
3. Fewer schemas in MongoDB;
4. You do not need to learn another language;
5. MongoDB has good PHP support.
1. MongoDB is a separate server
Just like MySQL and PostgreSQL, MongoDB will listen for links to the access. It provides tool functions including asking, creating, updating and deleting. In theory, you'll work like MySQL and PostgreSQL: link, process, and then close the link.
2. Say goodbye to the lines and tables, welcome documents and Collectors
Instead of the tables and rows that store the data, MongoDB stores the data in the document. If we have an "article" with a title, it has multiple authors, a theme and a tag. All this looks like the following:
Copy CodeThe code is 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 one record-this document-yes, it does store it like a document that supports composite forms of values stored in the same region. No longer need to be structured, and data should not be differentiated 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 document type, you don't have to tell the database anything. Even if you put the new data in the database.
In the 2nd, I modeled a document. Now I want to define an article type for all regions, all I need to do is write this data to 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 mandatory system, like JavaScript or PHP. In this way, the database is very good at weakening the role of the type.
There are some loopholes (very large amounts of data require some explicit definition), but in most cases, you write your MongoDB code just as you would 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, you can't use them on MongoDB.
MongoDB (which contains its PHP driver) does not need to ask for a language. In most cases, you just need to simply give a pointer to the specific formulation you need, and then return you to a document pointing.
If you run some higher-order functions (such as map-reduce), you can add them to MongoDB through a JavaScript application and run them in the JavaScript internal engine.
5. is PHP and MongoDB a natural pair?
PHP has very good support for MongoDB. The MONGO driver can be added as a pecl add-in to PHP, which means installing MONGO as if it were running pecl.
See here, you can start to write the MONGO API. More broadly, it is lined up with PDO. Not a simple demise, but definitely different from the database we developed earlier.
The API's documentation will include a bootstrap and a number of examples so you can bootstrap in a short period of time. The following will be useful tips for you.
MongoDB develops very fast.
Development time is very short, there is no too many patterns to manage, and little (if any) data maps.
Because there is no new query language to learn, the code is very small. After all, you don't need another ORM, and the packet is very light.
Your code is the promise of the future, and it's easier to add more areas 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-based database that can be used in many scenarios to replace traditional relational databases or key/value storage methods. MONGO is developed using C + + and provides the following features:
Collection-oriented storage:Suitable for storing data in the form of objects and JSON.
Dynamic Query:The MONGO supports rich query expressions. Query directives use a JSON-style tag to easily query objects and arrays embedded in the document.
Full index support:Includes inline objects and arrays of documents. The query optimizer of MONGO parses 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 and supports replication between master-slave mode and server. The primary goal of replication is to provide redundancy and automatic failover.
efficient and traditional storage methods:Supports binary data and large objects (such as photos or pictures).
automatic sharding to support cloud-level scalability (in the early alpha phase):The automatic sharding feature supports a level of DB cluster, which adds additional machines dynamically.
The main goal of MongoDB is to set up a bridge between key/value storage (which provides high performance and high scalability) as well as 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:The MONGO is ideal for real-time insertions, updates and queries, as well as the replication and high scalability required for real-time data storage on the site.
Cache:Due to 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 sources.
large-size, low-value data:While storing some data in a traditional relational database can be expensive, many times programmers often choose traditional files for storage.
High-scalability scenarios:The MONGO is ideal for databases consisting of dozens of or hundreds of servers. Built-in support for the MapReduce engine is already included in the roadmap for MONGO.
storage for objects and JSON data:MONGO's Bson data format is ideal for storing and querying in a document format.
Naturally, the use of MongoDB will also have some limitations, such as it does not fit:
a highly transactional system:such as banking or accounting systems. The traditional relational database is still more suitable for applications that require a large number of atomic complex transactions.
Traditional Business intelligence applications:A bi database that is specific to a particular problem will produce highly optimized queries. For such applications, the Data warehouse may be a more appropriate choice.
An issue that requires SQL.
MongoDB supports operating systems such as OS X, Linux, and Windows, and provides drivers for the Python,php,ruby,java and C + + languages, as well as drivers for Erlang and. NET platforms.

http://www.bkjia.com/PHPjc/327248.html www.bkjia.com true http://www.bkjia.com/PHPjc/327248.html techarticle 2010 should be remembered, because SQL will die this year. This year the relational database is dying, and this year developers find that they don't have to work hard for a long time to construct columns or tables ...

  • 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.