Introduction MongoDB installation
About can refer to the mounting MongoDB: https://www.cnblogs.com/DragonFire/p/9135630.html
In addition to the official website to download, you can download others to download the installation package good share: link: https://pan.baidu.com/s/139_BqPbh0IPcDMPmkWnS8w Password: fybs
The basic use of MongoDB
1. configure the environment variables (db default disk installed in c Program Files folder)
2. Open the db in two ways:
A disk data created in the c folder, the folder in which to create db c: \ data \ db, then cmd in mongod turn on the server (because the data is stored by default in c: \ data \ in db)
Two open cmd server directly, mongod --dbpath + custom folders. (Eg: mongod --dbpath c: \ shuju)
3. Use db database:
Enter mongo Enter cmd in a new window (db-step open command window can not be closed)
View a list of all databases: show dbs
Use and create a database: use + database name (database must be inserted at least one data will really create success)
Data directly into the database can not only to set (Collections) inserted data. Do not need to create a collection, only write dot syntax: db.student.insert ({ "name": "xiaoming"});
db dynamically created set, if db.student.insert ({ "name": "xiaoming"}); no student, is created in the insertion set of student data.
Remove the current database: db.dropDatabase ();
DB (Database) => collections (set) => json (data)
By data - deleted - change - Charles
insert:
1.db.student.insert ({"name":"xiaoming"});
2.db.student.insertOne ({"name":"xiaoming"});
3. Insert a plurality of data: db.student.insertMany ([{ "name": "xiaoming"}, { "name" hy: ""}]);
4. console insert multiple data too much trouble, we can also introduce json data externally written:
mongoimport --db test --collections restaurants --dorp --file primer-dataset.json
test: want to import database
restaurants: want to import collection
primer-dataset.json: import json data path (including the file name)
例:mongoimport --db xuexiao --collections student --dorp --file c:\user\data.json
Find:
db.student.find (); find all data set
db.student.findOne (); first
db.student.find ({ "name": "hy"}); hy lookup name for all data, a plurality of conditions are separated by commas
db.student.find ({ "sroce.shuxue" : {$ gt: 50} }); math scores greater than 50 to find (as less than $ lt) {..., ..., "sroce": { "shuxue ": 60," yuwen ": 99}, ..., ...,}
db.student.find ({ $ or : [{ "age": 9}, { "age": 11}] }); lookup age of 9 or age data 11
modify
db.student.updata ({ "name": "Xiao Ming"}, {$ set: { "age": 16}}); look for the name of Xiao Ming, to change the age to 16 years old.
db.student.updataOne();
db.student.updataMany();
delete
db.student.deleteOne({"name":"hy"});
db.student.deleteMany();