Home > Web Front-end > JS Tutorial > PHP extension to mongodb (first acquaintance)_javascript skills

PHP extension to mongodb (first acquaintance)_javascript skills

WBOY
Release: 2016-05-16 17:48:26
Original
1274 people have browsed it

Under the coercion of the blogger, I would like to share a little with you. I hereby declare that the blogger is very simple and honest. This is just a coercion, and there is absolutely no inducement.
Since there is less Chinese information related to mongodb, I will continue to share it with you if I have the opportunity. I hope this little sharing can bring something to everyone. Let’s get back to the point, please read on.

Why do you say "we met each other for the first time"? Because the data storage format of mongodb is a kind of data storage format. MongoDB's document structure is BJSON format (full name of BJSON: BinaryJSON), and the BJSON format itself supports saving data in binary format. , so the binary format data of the file can be saved directly into the MongoDB document structure.

MongoDB is composed of three levels: database, collection, and document object. Correspondence between
and relational database:

Relational database MongoDB database

Database database
table collection

Row document
can be used in MongoDB When creating an index, there is a default hidden field _id in the collection.

Installation and use

Install mongodb under windows and simply use mongodb command
1. Download and unzip the file
Go to the official website to download the appropriate version http:/ /www.mongodb.org/downloads
For example: http://fastdl.mongodb.org/win32/mongodb-win32-i386-2.2.1.zip
Unzip and place it under the corresponding drive letter, for example : D:mongodb
2. Installation
1. Add the bin directory to the environment variable D:mongodbbin
2. Create a data folder under D:mongodb to store data. You also need to create a db folder under the data file. Without the db folder, mongodb cannot start normally
3. Simple method to start mongodb:
Enter the bin directory

Copy code The code is as follows:

C:Documents and Settingsme>D:
D:>cd mongodb/bin
D: mongodbbin>mongod –dbpath D:/mongodb/data
D:mongodbbin>mongod –dbpath D:/mongodb/data

The following content is displayed:
Sun Jan 16 14:56:03 MongoDB starting: pid=860 port=27017 dbpath=D:/mongodb/d
ata 32-bit

** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data

** see http://blog.mongodb.org/post/137788967/32-bit-limitations

Sun Jan 16 14:56:03 db version v2.2.1, pdfile version 4.5
Sun Jan 16 14:56:03 git version: 0eb017e9b2828155a67c5612183337b89e12e291
Sun Jan 16 14:56:03 sys info: windows (5, 1, 2600, 2, 'Service Pack 3 ′) BOOST_LI
B_VERSION=1_35
Sun Jan 16 14:56:03 [initandlisten] waiting for connections on port 27017
Sun Jan 16 14:56:03 [websvr] web admin interface listening on port 28017

Note: You must first create the data folder and execute it in the bin directory. The default connection port of the mongoDB server is 27017

2. Add it to the registry to start as a Windows service. Like mysql, the service will be automatically started when Windows is started. Go to the bin directory and execute
Copy code The code is as follows:

D:mongodbbin>mongod --logpath D:mongodbloglog1.log --logappend
-- dbpath D:mongodbdata --directoryperdb --serviceName mongodb –install

After completion, output the following content (anti-virus software such as 360 will block it and need to be allowed to pass)
all output going to: D:mongodblogslog1 .log
Creating service mongodb
Service creation successful.
Service can be started from the command line via 'net start “mongodb″'.

D:mongodbbin>

Among them: loglog1.log log is output in append mode, –serviceName mongodb is the service name
Start MongoDB: net start mongodb
Stop MongoDB: net stop mongodb
Note: Restart after adding to the registry The computer can see that it has been started in the service item, but the service is still not started. When restarting the service, it is found that it is blocked by 360 Security Guards and needs to be confirmed again before it can be started.

3. A simple command to use mongodb. Go to the bin command and execute mongo.exe to enter the management interface. The default is to enter the test account.
Copy code The code is as follows:

D:mongodbbin>mongo.exe
MongoDB shell version: 2.2.1
connecting to: test
> show dbs;
admin
local

> help;View command prompt


3. Next, the same operation as for all databases requires adding a user’s defense permission
But the user created at this time does not have the permission to view the collection. What to do! In fact, it's easy to handle. I've already had a headache for everyone, so students who can persist in seeing this with their heart won't have any more headaches.
Execute the following command in the mongo.exe management interface you just entered

Copy the code The code is as follows:

>use admin
>db.auth("sa","sa")
>use web
>show collections

This time It's clear now.

4. MongoDB can create a database using use as follows: use web; This will create a database
Switch to the web database. If it does not exist, it will automatically be inserted after the data is inserted. Create one, and you can see a new web folder in the data directory
Copy the code The code is as follows:

> use web;

switched to db web
> db.my.save({a:10}); Save a message to collection my if it does not exist collection will automatically create a
> db.my.find(); retrieve all records
{ “_id” : ObjectId(“4d32c9204e6100000000691e”), “a” : 10 }
> show collections;
my
system.indexes
>exit;Exit

The installation and user permission settings of Mongodb have ended.
The following introduces several graphics management tools
1. Use the graphics management tool "MongoVUE 0.9.7.2"


You can see it after entering


2. A more recommended management software is "rockmongo"
It needs the support of PHP operating environment. I prefer it because PHP programmers have a ready-made environment and don't need to use it in vain, haha .
(1). Download a rockmongo, unzip it and put it in the web directory. Download address: http://rockmongo.com/downloads
If you don’t have a PHP operating environment but want to use rockmongo, you can Integrate package download in the download address.
(2). Download a php_mongo.dll that supports mongodb. Download address: https://github.com/mongodb/mongo-php-driver/downloads
(3). Add it to php.ini This line of code extension=php_mongo.dll Then restart apache and check php_info


means the installation has been successful
(4). Enter the address of rockmongo in the browser, a login box will appear, and you can log in. The default user is: admin Password: admin
There are many other tools, you can explore slowly.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template