Five things you should know about MongoDB as an PHP programmer

  • 2020-06-03 06:03:08
  • OfStack

2010 should be remembered as the year SQL dies. A year into relational databases, developers are finding that they don't need to spend a lot of time building columns or tables to hold data.
2010 will be the start year for document-type databases. Although this trend has been going on for years, it is only now that there are more and more widely documented databases. From cloud-based Amazon to Google, a host of open source tools, and CouchDB and MongoDB have followed.
So what is MongoDB? Here are five things PHP developers should know:
1. MongoDB is a separate server;
MongoDB is document-based, not table-based;
3. Schema is less in 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 PostgreSQL1, MongoDB listens for incoming links. It provides tools for query, create, update, and delete. In theory, you'll do what you did in MySQL and PostgreSQL1: link, process, and then close the link.
Say goodbye to rows and tables, and welcome documents and collectors
Instead of tables and rows that store data, MongoDB stores data in documents. Suppose we have an "article" with a title that has multiple authors, a topic, and a tag. All of this looks like the following:

'title'=>'Hello World',
'body'=>'Hello world',

The key in the above example is that 1 record -- this document -- yes, it does store as 1 document, supporting the compound form of values stored in the same area. There is no need to structure, no need to separate data into tables. Therefore, the table no longer exists.
3. MongoDB contains less schema
MongoDB has no schema language. If you want to create a new document type, you don't have to tell the database anything. Just put the new data in the database.
In point 2, I simulate a document. Now I want to define an article type for all areas, all I need to do is write the data to the database. What if I decide to delay writing? All I have to do is pull out the data, add the date field, and save it.
So what about data types? The short answer is that MongoDB USES a mandatory system, similar to JavaScript or PHP. In this way, the database nicely weakens the role of type.
There are a few bugs here (a huge amount of data requires some clear definitions), but most of the time, writing your MongoDB code is like programming it on PHP.
4. You don't need to learn another language
Recall 1 of the other database abstraction layers you've written about. Remember all the ORM layers you have used. Then you can abandon them now. You won't need them on MongoDB.
MongoDB(including its PHP driver) does not require an inquiry language. In most cases, you simply specify what you want given 1 pointer, and then return you 1 document pointer.
If you run some higher-order functions like ES56en-ES57en, you can add them to MongoDB via the JavaScript application and run the scripts in the JavaScript internal engine.
5. PHP and MongoDB are born 1 pair?
PHP already has good support for MongoDB. The Mongo driver can be added to PHP as one PECL add-on, which means that it will install Mongo just like running PECL1.
Here, you can start writing API for Mongo. More broadly, it's on a par with the PDO. Not a simple death, but definitely different from the databases we've developed before.
API's documentation will include a boot and many examples so you can bootstrap in a short time. The following tips will be useful for your 10 points.
MongoDB is growing very fast.
The development time is very short, there are not many schemas to manage, and very few (if any) data mappings.
Because there is no new query language to learn, the code tweaks are minimal. After all, you don't need another ORM, and the packet is very light.
Your code is a guarantee of the future, making it easier to add more domains, even more complex ones, to your objects. So your code can easily adapt to changing requirements.
Mongo is a high-performance, open source, schemaless document database that can be used in many scenarios as an alternative to traditional relational databases or key/value stores. Developed using C++, Mongo provides the following functions:
◆ Collection-oriented storage: Suitable for storing data in the form of object and JSON.
◆ Dynamic query: Mongo supports rich query expressions. Query directives use tags in the form of JSON to easily query objects and arrays embedded in documents.
◆ Complete index support: includes document embedded objects and arrays. Mongo's query optimizer analyzes 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, master-slave mode and replication between servers. The primary goal of replication is to provide redundancy and automatic failover.
◆ Efficient traditional storage: support base 2 data and large objects (such as photos or pictures).
◆ Automatic sharding to support cloud-level scalability (in the early alpha phase) : Automatic sharding supports horizontal database clustering with the ability to dynamically add additional machines.
The primary goal of MongoDB is to bridge the gap between key/value storage (which provides high performance and high scalability) and the traditional RDBMS system (rich functionality). According to the official website, Mongo is suitable for the following scenarios:
◆ Website data: Mongo is very suitable for real-time insertion, update and query, and has the replication and high scalability required for website real-time data storage.
◆ Caching: Due to its high performance, Mongo is also suitable as a caching layer for information infrastructure. After a system restart, the persistent cache layer built by Mongo avoids overloading the underlying data sources.
◆ Large size, low value data: It can be expensive to store data using a traditional relational database.
◆ Highly scalable scenario: Mongo is ideal for databases with 10 or hundreds of servers. The Mongo roadmap includes built-in support for the MapReduce engine.
◆ For object and JSON data storage: Mongo's BSON data format is very suitable for document format storage and query.
Naturally, the use of MongoDB also has some limitations, such as that it is not suitable for:
◆ Highly transactional systems, such as banking or accounting systems. Traditional relational databases are still more suitable for applications that require a large number of atomically complex transactions.
◆ Traditional BUSINESS intelligence applications: the BI database for a specific problem produces highly optimized queries. For such applications, a data warehouse may be a more appropriate choice.
◆ Questions requiring SQL.
MongoDB supports OS X, Linux, Windows and other operating systems, and provides drivers for Python, PHP, Ruby, Java and C++ languages, and the community also provides drivers for Erlang and.NET and other platforms.

Related articles: