MongoDB Installation
Official website: https://www.mongodb.com/
Brochure: https://docs.mongodb.org/manual/
Win7 system needs to install patches, KB2731284
- Setup finishes configuring environment variables:
- C:\Program Files\mongodb\server\3.0\bin added to the system's PATH environment variable
Basic commands
- Gongod: Boot
- Mongoimport Importing Data
- MONGO use the database, the environment after running this command is MONGO syntax.
- Show DBS: List all databases
- Use database name: using a database
- DB: View your current database
Note: If you use a database that does not exist, it is new, but only after you execute the INSERT Data statement can you create a new success.
Use of the database
To manage the database, you must turn on the boot, use the mongod--dbpath c:\mongom Command (--dbpath is the folder where the database document is selected)
1. Inserting data
2. Querying data
Search All
db.restaurants.find()
Multiple conditions
db.student.find({"score.shuxue":80 , "age":22})
Greater than condition
db.student.find({"score.yuwen":{$gt:60}});
Or
db.student.find({$or:[{"age":18},{"age":22}]});
Sort
db.restaurants.find().sort( { "borough": 1, "address.zipcode": 1 } )
3. Modify the data
Single Data modification
db.student.update({"name":"小明"},{$set:{"age":22}});
Change multiple matching data (plus multi parameter)
db.student.update({"score.shuxue":80},{$set:{"age":26}},{multi: true});
Complete replacement (without $set keyword)
db.student.update({"name":"小明"},{"name":"大明","age":28});
4. Delete data
MongoDB Configuration and basic usage