Preface:
MongoDB is a database based on distributed file storage. Designed by C + + to provide scalable, high-performance data storage solutions for Web applications.
Official website: https://www.mongodb.com/
This tutorial is only for Windows systems
Step one: Download MongoDB
Address: http://dl.mongodb.org/dl/win32/x86_64
Download Mongodb-win32-x86_64-2008plus-ssl-v3.4-latest.zip here and unzip it in D:\mongodb (where the path can be chosen by itself) as shown in:
Step Two: Create a folder db, log
Create your own folders d:\mongodb\data\db, D:\mongodb\data\log, respectively, to install the DB and log files.
Step three: command-line installation
Run cmd.exe into the DOS command interface and execute the following command
>> CD D:\mongodb\bin
> >>d:\mongodb\bin>mongod-dbpath=d:\mongodb\data\db
The default MongoDB listener port is 27017,mysql 3306
Step Four: Verifying the installation
DOS command interface, after the installation is complete, open http://127.0.0.1:27017/, see the following prompt, indicating that the installation was successful.
Step five: Set MongoDB as a Windows service
Every time I want to use the MongoDB database to open the Mongod.exe program, so it is more troublesome, at this time we can install MongoDB as a Windows service
DOS command interface, execute the following command:
>> CD D:\mongodb\bin
>>mongod--dbpath "d:\mongodb\data\db"--logpath "D:\mongodb\data\log\MongoDB.log"--install--servicename " MongoDB "
Where MongoDB.log is the log file that was started,--servicename the "MongoDB" service named MongoDB
We can see the MongoDB created on the Windows Services page.
Step Six: Start the MongoDB service
DOS command interface, execute the following command:
NET START MongoDB
Step Seven: Open the MongoDB shell
DOS command interface, execute the following command: MONGO, open the shell, in fact, the shell is the client of MongoDB
Step Eight: Close the service and delete the process
DOS command interface, execute the following command:
>> netstop MongoDB (off service)
>> mongod--dbpath "d:\mongodb\data\db"--logpath "D:\mongodb\data\log\MongoDB.log"--remove--servicename " MongoDB "(Delete, note not--install)
Step nine: MongoDB common commands
1. Common commands
Show DBS Display Database list
Use dbname Enter dbname database, case sensitive
Show Collections displays a collection in the database, equivalent to a table
2. Create & Add
Db.users.save ({"Name": "Jack"}) created a collection named users and added a new {"Name": "LECAF"} data
Db.users.insert ({"Name": "Jack", "Age": 20}) Inserts a new data into the Users collection, and if there is no users this collection, MongoDB automatically creates
3. Delete
Db.users.remove () Delete all data under the Users collection
Db.users.remove ({"Name": "Jack"}) delete Name=jack data under the Users collection
Db.users.drop () or Db.runcommand ({"Drop", "users"}) Delete collection users
Db.runcommand ({"Dropdatabase": 1}) Delete the current database
4. Find
Db.users.find () Find all data in the Users collection
Db.users.findOne () to find the first data in the Users collection
5. Modifications
Db.users.update ({"Name": "Jack"}, {"Age": 50}) Modify the Name=jack data to age=50
The first parameter is the lookup condition, the second parameter is the modification, except the primary key, the other content is replaced by the contents of the second parameter, the primary key cannot be modified.
Continue to study, if there are left, follow-up supplement ~ ~ ~
MongoDB Installation Tutorials