MongoDB the installation steps under Windows to share _mongodb

Source: Internet
Author: User
Tags bulk insert mongodb
NoSQL is very hot, mongodb as a good distributed file storage database, also received a lot of attention, Http://weibo.com/k/mongodb Sina Weibo in the daily now about more than 20 information.

Official website: http://www.mongodb.org/
Download: http://www.mongodb.org/downloads
PHP Extensions: Http://cn.php.net/mongo

I chose the Windows Installer package and downloaded the 1.8.2 version of Windows 32-bit, which is the following installation record:

Unzipped to D:\www\mongodb.

CD d:\www
Bin\mongod.exe--dbpath=d:/www/mongodb/data

Sat June 09:03:28 [Initandlisten] db version v1.8.2, pdfile version 4.5
Copy Code code as follows:

Sat June 09:03:28 [Initandlisten] git Version:433bbaa14aaba6860da15bd4de8edf6
00f56501b
Sat June 09:03:28 [Initandlisten] Build sys info:windows (5, 1, 2600, 2, ' Ser
Vice Pack 3 ') boost_lib_version=1_35
Sat June 09:03:28 [Initandlisten] waiting for connections on port 27017
Sat June 09:03:28 [WEBSVR] Web admin interface listening on port 28017

So the MongoDB is running, but DOS operation is not closed, a shutdown. Therefore, it needs to be set as a system service:
D:\www\mongodb>bin\mongod.exe--dbpath=d:/www/mongodb/data--logpath=d:/www/mongodb/mongodb.log--install
Copy Code code as follows:

All output Going To:d:/www/mongodb/mongodb.log
Creating Service MongoDB.
Service creation successful.
Service can is started from the command line via ' net start ' MongoDB '.

This makes it possible to have a MongoDB service in the system service (SERVICES.MSC) that can be set up to automatically allow Windows to automatically start MONGO DB each time it starts.
Look at the client with its own, still in its bin directory, file name Mongo.exe
Bin\mongo.exe
Copy Code code as follows:

MongoDB Shell version:1.8.2
Connecting To:test

In Http://cn.php.net/mongo download MongoDB PHP extensions, PHP 5.2 VC6 thread-safe Mongo.
The 5.2 edition has only 5.2.13 Mongodb.dll. Local PHP Reload 5.2.13, it's ready to use.
Main code:
Copy Code code as follows:

$m = new Mongo (); Default connection 27017 port on this machine
$mdb = $m-> hx; Select HX Database, if not previously, it will be created automatically, or you can use $M->SELECTDB ("HX");
$collection = $mdb->hx_site; Select the Hx_site set inside the HX, which is equivalent to taking the Hx_site table in the HX library, or using $mdb->selectcollection ("Hx_site");
[HTML]
BULK INSERT:
[Code]
For ($i =53 $i <84; $i + +) {
$start = $i * 10000;
$end = ($i + 1) * 10000;
$sql = "SELECT * from Hx_site WHERE ID > $start and ID <= $end";
$tmp = $db->query ($sql);
$arrs = Array ();
while ($arr = $db->fetch_array ($tmp)) {
$arrs [] = $arr;
}
$collection->batchinsert ($ARRS);
}

PHP will be a local 83.6w data mysql into MongoDB, each insert 1w, one need 109~125ms.
Copy Code code as follows:

/*
MongoDB syntax corresponding to MySQL statements: http://www.jb51.net/article/28694.htm
Take pagerank=5, reverse by ID, take 30 strips
Similar to SELECT * from hx_site WHERE PageRank = 5 order by ID DESC LIMIT 30
*/
$cursor = $collection->find (Array (' PageRank ' => ' 5 '))->sort (array (' ID ' =>-1))->limit (30);
foreach ($cursor as $obj) {//Traverse documents in all collections
echo $obj ["id"]. '. $obj [' domain ']. "<br>";
}

No index of the case to take a record, 656ms,mysql need 0.7s, basically no difference.
COUNT (*) a condition, more than 800 ms, plus 100 ms after index
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.