mongodb installation steps Shared under windows

  • 2020-05-06 11:57:51
  • OfStack

nosql very fire, mongodb as an excellent distributed file storage database, it has received considerable attention, http: / / weibo com k/mongodb sina weibo than there are about 20 a day in the information.

Liverpoolfc.tv: http: / / www. mongodb. org/
Download: http: / / www. mongodb. org/downloads
PHP extension: http: / / cn php. net/mongo

I selected the windows installation package and downloaded version 1.8.2 of Windows 32-bit. Here is the installation record:

Unzip to D:\www\mongodb

cd d:\www
bin\mongod.exe --dbpath=d:/www/mongodb/data

Sat Jul 09 09:03:28 [initandlisten] db version v1.8.2, pdfile version 4.5
 
Sat Jul 09 09:03:28 [initandlisten] git version: 433bbaa14aaba6860da15bd4de8edf6 
00f56501b 
Sat Jul 09 09:03:28 [initandlisten] build sys info: windows (5, 1, 2600, 2, 'Ser 
vice Pack 3') BOOST_LIB_VERSION=1_35 
Sat Jul 09 09:03:28 [initandlisten] waiting for connections on port 27017 
Sat Jul 09 09:03:28 [websvr] web admin interface listening on port 28017 

So mongodb is running, but the DOS operation can't be shut down. So you need to set it as a system service:
D:\www\mongodb > bin\mongod.exe --dbpath=d:/www/mongodb/data --logpath=d:/www/mongodb/mongodb.log --install
 
all output going to: d:/www/mongodb/mongodb.log 
Creating service MongoDB. 
Service creation successful. 
Service can be started from the command line via 'net start "MongoDB"'. 

This adds an MongoDB service to the system service (services.msc), which can be set to automatically enable windows to start Mongo DB every time it starts.
Now let's look at its own client, still in its bin directory, mongo.exe
bin\mongo.exe
 
MongoDB shell version: 1.8.2 
connecting to: test 

In http: / / cn. php. net/download mongo mongodb php extension, PHP 5.2 VC6 Thread - Safe Mongo extension.
Version 5.2 has only 5.2.13 of mongodb.dll. The local php has been reinstalled with 5.2.13 and is ready to use.
Main code:
 
$m = new Mongo(); //  The default connection is native 27017 port  
$mdb = $m -> hx; //  choose hx A database, if not previously created, is also available $m->selectDB("hx"); 
$collection = $mdb->hx_site; // choose hx The inside of the hx_site Set is the same thing as taking hx In the database hx_site Tables can also be used $mdb->selectCollection("hx_site"); 
[html] 
 Batch 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 is used to convert mysql with 83.6w pieces of data locally into mongodb. Each insertion of 1w pieces requires 109~125ms.
 
/* 
mysql Statement corresponding mongodb Grammar:  //www.jb51.net/article/28694.htm
 take pagerank=5 According to the id Reverse order, 30 article  
 Similar to the  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) { // Iterate through the documents in all collections  
echo $obj["id"].' '.$obj["domain"] . "<br>"; 
} 

Taking a record without an index, 656ms, mysql requires 0.7s, which is basically the same thing.
count(*) a condition, more than 800 ms, more than 100 ms indexed

Related articles: