PHP programmers should understand five things MongoDB

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags applications array based cloud code data developers document

2010 should be remembered because SQL will die this year. This year, the relational database is on the verge of falling, and this year developers found they no longer needed long, laborious columns or tables to store data.

2010 will be the starting year for document databases. Although this momentum has lasted for many years, it is now the era of more and broader document-based databases. From cloud-based Amazon to Google, a large number of open source tools, and the ensuing CouchDB and MongoDB.

So what is MongoDB? Here are five things PHP developers should know about:

1. MongoDB is a separate server;

MongoDB is based on the document, not based on the table;

3. Fewer Schemas in MongoDB;

You do not need to learn another language;

MongoDB has good PHP support.

1. MongoDB is a separate server

Like MySQL and PostgreSQL, MongoDB will listen for incoming links. It provides the tools to include asking, creating, updating, and deleting. In theory, you will work the same as MySQL and PostgreSQL: link, process, and then close the link.

2. To say goodbye to rows and tables, welcome documents and collectors

Instead of storing tables and rows of data, MongoDB stores the data in the document. If we have a titled "article," it has multiple authors, a topic, and a label. All of these look like the following:

array (

'title' => 'Hello World',

'authors' => array ('John', 'Sally', 'Jim'),

'body' => 'Hello world',

'tags' => array ('tag1', 'tag2', 'tag3')

);

?>

The key thing in the above example is that one record - this document - yes, indeed stored as a document that supports the composite form of values ​​stored in the same area. No longer need to structure, do not need to distinguish the data in accordance with the table. Therefore, the table does not exist.

MongoDB contains fewer schemas

MongoDB does not have a schema language. If you want to create a new document type, you do not need to tell the database anything. Although the new data into the database on the line.

In the second point, I simulated a document. Now I want to define an article type for all regions, all I need to do is write the data to the database. If I decide to postpone writing? I just need to pull this part of the data, add the date field, and save it last.

So what to do with the data type? The simple answer is that MongoDB uses a coercion system like JavaScript or PHP. In this way, the database is extremely good at weakening the type's effect.

There are some bugs (very large amounts of data require some definitive definition), but in most cases you write your MongoDB code just as you would on PHP.

You do not need to learn another language

Recall the other database abstraction layers you've written. Recall all the ORM layers you've used before. Then you can now abandon them, you do not need them on MongoDB.

MongoDB (including its PHP driver) does not need to ask the language. In most cases, you simply need to give a pointer to exactly what you need, then return you with a document to point to.

If you run some higher-order functions (such as Map-Reduce), you can add them to MongoDB via a JavaScript application and run them in the JavaScript internal engine.

PHP and MongoDB is a natural pair?

PHP already has good support for MongoDB. The Mongo driver can be added to PHP as a PECL add-in, which means that installing it is like installing Mongo like running PECL.

See here, you can start writing Mongo API. More broadly, it's with PDO. Not a simple demise, but absolutely different from the database we developed earlier.

The API's documentation will include a guide and many examples so you can bootstrap in a short time. The following will be very useful tips for you.

MongoDB is growing very fast.

Development time is very short, there is not too much mode to manage, very little (if any) data mapping.

Because there is no new query language to learn, the code adjustment is small. After all, you do not need another ORM and the packets are very light.

Your code is a guarantee of the future, you can more easily add more areas for your object, and even more complex areas. So your code can easily adapt to changes in demand.

Extend reading

Mongo is a high-performance, open-source, schema-free, document-based database that can be used in many scenarios to replace traditional relational databases or key / value storage. Developed using C ++, Mongo provides the following features:

◆ Collection-oriented storage: suitable for storing objects and JSON data.

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

◆ complete index support: including document embedded objects and arrays. Mongo's query optimizer parses the query expression and generates an efficient query plan.

◆ Query Monitoring: Mongo includes a monitoring tool for analyzing the performance of database operations.

◆ Replication and automatic failover: The Mongo database supports data replication between servers, supporting master-slave mode and server-to-server replication. The main goal of replication is to provide redundancy and automatic failover.

Efficient traditional storage: support for binary data and large objects (such as photos or pictures).

◆ Auto-sharding to support cloud-level scalability (in early alpha phases): Auto-sharding supports a level database cluster that dynamically adds extra machines.

The primary goal of MongoDB is to bridge the gap between key / value storage (providing high performance and scalability) as well as traditional RDBMS systems (rich functionality). According to the official website description, Mongo suitable for the following scenarios:

◆ Website Data: Mongo is ideally suited for real-time insertion, updating and querying, as well as the replication and scalability required for web site real-time data storage.

Caching: Due to its high performance, Mongo is also suitable as a caching layer for information infrastructure. After the system is restarted, the persistent cache layer built by Mongo can avoid overloading the underlying data source.

Large-size, low-value data: Using traditional relational databases to store some data can be expensive, and many times programmers often choose traditional files for storage.

High scalability scenarios: Mongo is ideal for databases consisting of tens or hundreds of servers. Mongo's roadmap already contains built-in support for the MapReduce engine.

◆ for the storage of objects and JSON data: Mongo's BSON data format is very suitable for the storage and query of the document format.

Naturally, the use of MongoDB will have some limitations, for example, it does not fit:

◆ highly transactional system: for example, bank or accounting system. The traditional relational database is still more suitable for applications that require a lot of atomic complexity of the transaction.

◆ Traditional Business Intelligence Applications: BI databases targeted at specific problems create highly-optimized queries. For such applications, the data warehouse may be a more suitable choice.

◆ need SQL problem.

MongoDB supports operating systems such as OS X, Linux and Windows. It also provides drivers for Python, PHP, Ruby, Java and C ++. Communities also provide drivers for Erlang and .NET platforms.

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.