official website http://www.mongodb.org
1, download Mongodb-win32-i386-latest.zip decompression
MongoDB 3.1.5 requires win7 to download and install memory patches HTTPS://SUPPORT.MICROSOFT.COM/ZH-CN/HOTFIX/KBHOTFIX?KBNUM=2731284&KBLN=ZH-CN
2, extract to the I:\MONGODB directory directory structure as follows I:\mongodb\bin i:\mongodb\data This directory if it does not exist to establish
3. Command Console Mongod.exe--version View the version number of the service program
Temporarily start the Mongod server. The window cannot be closed. I:\mongodb\bin>mongod--storageengine=mmapv1--dbpath i:\mongodb\data--journal--logpath i:\mongodb\log\log.txt
4. Install server Mongodb\bin>mongod--install--servicename mongodb--logpath i:\mongodb\log\log.txt--logappend--dbpath i:\ Mongodb\data–directoryperdb
Installing the MongoDB service process Mongod.exe--install--servicename MongoDB--storageengine=mmapv1--logpath f:\mongodb\log\log.txt-- Logappend--dbpath f:\mongodb\data-directoryperdb--journalmongod.exe--remove--storageengine=mmapv1--servicename MongoDB--logpath i:\mongodb\log\log.txt--logappend--dbpath i:\mongodb\data-directoryperdb--journal
Mysqld mongod main process MySQL MONGO client installation service Mongod--install--servicename mongodb--storageengine=mmapv1--dbpath f:\mongodb\ Data--journal--logpath F:\mongodb\log\log.txt
Mongod--install--servicename mongodb--storageengine=mmapv1--dbpath f:\mongodb\data--directoryperdb--journal-- LogPath f:\mongodb\log\log.txt--logappendmongod--remove--servicename mongodb--storageengine=mmapv1--dbpath i:\ Mongodb\data--directoryperdb--journal--logpath i:\mongodb\log\log.txt--logappend
Stop net stop MongoDB offload service Mongod--remove--servicename MongoDB startup net start MongoDB
Uninstall Service Mongod--remove--servicename mongodb--storageengine=mmapv1--dbpath i:\mongodb\data--journal--logpath i:\ Mongodb\log\log.txt
Log on to the MONGO database server
I:\mongodb\bin>mongo Enter
>db.version ();
>cls Clear Screen Command
Set up a database
Use database; Db. collection name. Save ({sanem: ' John Doe ', sage:18,saddress: "Zhengzhou"});d B. collection name. Find (); SELECT * from table name;
Show DBS; View all databases
Show tables; the two are equal show collections;
Db.stu.save ({name: "John Doe", Age:22,address: "Zhengzhou"});d B.stu.save ({name: "Zhao Liu", age:22,address: "Zhengzhou"});d B.stu.save ({name: "Zhang San", Age:22,address: "Zhengzhou"});d B.stu.save ({name: "Zhang Sanfeng", age:22,address: "Zhengzhou"});d B.stu.save ({name: "Li Yong", Age:22, Address: "Zhengzhou"});
Mongod--dbpath i:\mongodb\data--journal--logpath i:\mongodb\log\log.txt
Mongod.exe--storageengine defaults--dbpath i:\mongodb\data--journal--logpath i:\mongodb\log\log.txt mongod.exe--st Orageengine wiredtiger--dbpath i:\mongodb\data--journal--logpath i:\mongodb\log\log.txt mongod--storageengine Wired Tiger--dbpath I:/mongodb/data
Hotfix KB2731284 or later update is not installed, would zero-out data files
Db.student.find (); View the data in the student table
View the status of a table/collection view the status of a library
Total number of records queried
View Help
Delete Database information and tables
Primary key conflict, save, Direct overwrite, insert primary key conflict can not be inserted > Db.user.remove ({}); Clears all documents in the user collection
> Db.user.remove ({_id:5});
> Db.user.remove ({account: ' RRRT '});
Db.user.remove ({"_id": ObjectId ("558e42ca6c8b9206ccef1a7d")}); Delete system-created ID data
Data query Db.user.find (); Equivalent to select * from User;db.user.find ({The attribute field},{to be displayed in the criteria area});
Db.user.find ({conditional area},{account:1,_id:false}); The result of the query shows only the ID and account number;
1true,0false;
Db.user.find ({_id: ($GT: 3)}), $lte less than or equal to $lt less than $gt greater than $gte greater than or equal to > db.user.find ({_id:{$gt: 1});
Query a beginning account > Db.user.find ({account:/^a.*$/});
The equivalent of select * from the user where account like ' a% ';
> Db.user.find ({account:/a/}); Find the
SELECT * from the user where account like '%a% ';
Double conditional query > Db.user.find ({_id:5,account: ' AA '});
Equivalent to select * from user where _id=4 and account= ' AA '; Db.user.save ({account: ' C3 ', age:20});
Db.user.save ({account: ' A2 ', age:18});
Db.user.save ({account: ' A1 ', age:18});
The query account equals A1, or the Db.user.find ({$or: [{account: ' A1 '},{age:{$gte: 18}]}), or older than or equal to 18, and delete the > db.user.remove ({age:{ $gte: 25}});
Showing 3 records > Db.user.find (). limit (3);
> Db.user.find (). Limit (2). Skip (2); page 22, show second page
Data modification, first set of conditions, second group change what
> db.user.update ({account: ' A1 '},{$set: {account: ' Myroot '}});
> db.user.update ({_id:5},{$set: {account: ' www ', password: ' 111 '}});
By default only one record is modified > db.user.update ({account: ' A1 '},{$set: {account: ' abc '}});
Multi:true Modifying Multiple document results
> db.user.update ({account: ' A1 '},{$set: {account: ' abc '}},{multi:true});
All ages modified to 88> db.user.update ({},{$set: {age:88},{multi:true}});
Everyone's score plus a > db.user.update ({},{$inc: {age:1}},{multi:true});
In the statistics account name, the total number of documents containing the B-letter equals the Select COUNT (*) from the user where accounts like '%b% ';> db.user.find ({account:/b/}); {"_id": ObjectId ("558e49a06c8b92> db.user.find ({account:/b/}). coun1 to all users, add a field, properties Love> db.user.update ( {},{$set: {love:[' music ', ' Play ']}},{multi:1});
Delete the properties of one of the listed documents $unset > Db.user.update ({},{$unset: {password:1}},{multi:1});
Modify the elements inside the array add a column $push $addToSet are joined > db.user.update ({_id:5},{$push: {love: ' Hit '}});
> db.user.update ({_id:5},{$addToSet: {love: ' Hit '}});
Move the last element in the divisor group > db.user.update ({_id:5},{$pop: {love:1}});
Delete Id:5 Music > db.user.update ({_id:5},{$pull: {love: ' Music '}});
> db.createcollection (' AA '); {"OK": 1} empty table in > Db.aa.drop ();
The batch execution JS script directly writes the JS constructs the database to build the table var conn= new Mongo ();//build the Library MyDB library var mydb=conn.getdb (' MyDB ');//Build table Hnsc_linkmydb.hnsc_link.save ({ Title: ' Baidu ', url: ' http://www.baidu.com ', img:null,flg:true});> load (' d:/a.js '); introduction of True> DB;
Establishment of empty table > db.createcollection (' CCC '); {"OK": 1}
Delete cc table > Db.ccc.drop (); truephp with mogodb driver download http://docs.mongodb.org
Http://pecl.php.net/package/mongo1, download Php_mongo-1.6.9-5.6-ts-vc11-x86.zip
Unzip the copy Php_mongo.dll to the i:/php/ext/directory
2. Open the php.ini file and add the following Php_mongo.dll
3, modify the apche/conf/httpd.conf
<directory/> allowoverride None Require all granted</directory>
# # # # # # # # #ScriptAlias/php/"i:/php/" AddType application/x-httpd-php. Phpaction application/x-httpd-php "/php" in CGI mode configuration /php-cgi.exe "
<?php//phpinfo (); $m = new Mongoclient (); Connection $db = $m->mydb; $c = $db->hnsc_link->find (); foreach ($c as $doc) {echo $doc [' title '];} Php-m said the missing DLL file, because the php.ini inside the file open too much, useless must be removed, the error is wrong for the log PDO connection MongoDB
<?php
$m = new MongoClient();
$db = $m->abc;
$coll = $db->user;
$c = $coll->find([]);
foreach ($c as $doc){
echo $doc[‘account‘].‘<br>‘;
}
From for notes (Wiz)
The installation and use of MongoDB