How to install mongodb in windows

Source: Internet
Author: User
Tags install mongodb

Nosql is very popular, mongodb as an excellent distributed file storage database, also got a lot of attention, http://weibo.com/k/mongodb Sina Weibo is now about 20 pieces of information every day.

Official Website: http://www.mongodb.org/
Download: http://www.mongodb.org/downloads
PHP Extension: http://cn.php.net/mongo

I chose the windows Installation Package and downloaded Windows 32-bit version 1.8.2. The following is the installation record:

Decompress the package 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.5Copy codeThe Code is as follows: 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 = listen 35
Sat Jul 09 09:03:28 [initandlisten] waiting for connectionon port 27017
Sat Jul 09 09:03:28 [websvr] web admin interface listening on port 28017

In this way, mongodb is running, but the DOS operation cannot be closed, and it will stop as soon as it is closed. Therefore, you need to set it as a system service:
D: \ www \ mongodb> bin \ mongod.exe -- dbpath = d:/www/mongodb/data -- logpath = d:/www/mongodb. log -- installCopy codeThe Code is as follows: all output going to: d:/www/mongodb. log
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via 'net start "MongoDB "'.

In this way, you can add a MongoDB service in the System Service (services. msc). You can set it to automatic to enable Mongo DB to be automatically started every time windows starts.
Next, we can see that the client is still in its BINLOG, and the file name is "cmd.exe ".
Bin \ cmd.exeCopy codeThe Code is as follows: MongoDB shell version: 1.8.2
Connecting to: test

Download the PHP extension of mongodbat at http://cn.php.net/mongo, PHP 5.2 VC6 Thread-Safe Mongo extension.
Version 5.2 only has mongodb. dll 5.2.13. Local php has been reinstalled 5.2.13 and can be used.
Main Code:Copy codeThe Code is as follows: $ m = new Mongo (); // The default connection is port 27017 of the local machine.
$ Mdb = $ m-> hx; // select the hx database. If not, it is automatically created. You can also use $ m-> selectDB ("hx ");
$ Collection = $ mdb-> hx_site; // select the hx_site set in hx, which is equivalent to the hx_site table in the hx database. You can also use $ 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 );
}

Use php to convert mysql with 109 million data records locally into mongodb. Each time data records are inserted ~ 125 ms.Copy codeThe Code is as follows :/*
Mongodb syntax corresponding to mysql statement: http://www.jb51.net/article/28694.htm
Pagerank = 5, 30 in descending order of IDS
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 all documents in the Set
Echo $ obj ["id"]. ''. $ obj [" domain "]." <br> ";
}

If no index is available, a record is taken for 656 ms. mysql needs 0.7 s, which is basically no difference.
Count (*) a condition with more than 800 ms, and more than 100 ms after the index is added

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.