Install and use mongodb in Windows

Source: Internet
Author: User

Install and use mongodb in Windows

--- Install the mongodb Service

Download the Windows 32bit installation package
My put in e: \ mongo
Put this path e: \ mongo in our computer environment variable.

Open cmd
Cd e: \ mongo
Mkdir db
Cd bin
Mongod -- dbpath = e: \ mongo \ db

If the configuration is successfully installed, a large amount of information will be returned.

 

--- Install PHP mongo Extension
1. Download The php_cmd.dll extension and put it in php \ ext \
2. Modify the extension = php_cmd.dll file of php. ini.
3. Restart the server
4. Open PHPinfo. If mongo-related information is displayed, the installation is successful.


--- Operate mongodb Databases
New cmd
Cd e: \ mongo \ bin
Mongo
It is directed to the test database by default.
# Create a collection
> Db. createCollection ('person ')
> {"OK": 1}

Add, delete, modify, and query
Db. person. insert ({"name": "bobo", "age" => 23 })
Db. person. remove ({"name": "bobo "})
Db. person. update ({"name": "bobo" },{ "age" => 299 })
Db. person. find ()


We can set a user password for each database.
> Use test # specify to the test Database
> Db. addUser ('root', "root ");
> WARNING: The 'adduser' shell helper is DEPRECATED. Please use 'createuser
Ad
Successfully added user: {"user": "test", "roles": ["dbOwner"]}


--- Install a mongodb database management tool
Like phpmyadmin, the name is RockMongo.


ThinkPHP framework link mongodb

Return array (
// 'Config maps '=> 'configuration value'
'Db _ type' => 'mongo ', // Database TYPE
'Db _ host' => 'localhost', // server address
'Db _ name' => 'test', // Database NAME
'Db _ user' => 'test', // USER Name
'Db _ pwd' => 'test', // Password
'Db _ port' => '123', // PORT
);


Create a PersonModel. class. php under Home \ Model
To Inherit
<? Php
Namespace Home \ Model;
Use Think \ Model \ custom Model;
Class PersonModel extends Model
{
// It can be empty.
}


Controller instance

Public function index (){
$ Rows = 2;
$ Count = D ('person ')-> count ();
$ Page = new \ Think \ Page ($ count, $ rows );
$ All = D ('person ')-> limit ($ Page-> firstRow.', '. $ Page-> listRows)-> select ();
Print_r ($ all );
}

Output result

Array ([580f1d3957df98eef53288f6] => Array ([_ id] => 580f1d3957df98eef53288f6 [keys] => 3 [name] => bbo [age] => 27) [580f1d4857df98eef53288f7] => Array ([_ id] => 580f1d4857df98eef53288f7 [keys] => 4 [name] => bsbo [age] => 28 ))

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.