MongoDB Database
View database: Show DBS;
Create/Switch database: Use F28 (F28 for database name)
To view a running database: DB;
Crud Additions and deletions (create retrive update delate)
Add: Insert
db.users.insert({username:"jack",password;123456})
Delete: Remove
Dropdatabase (); Delete the current database
Db.users.remove ({username: "aaaaaa"})//delete only this piece of data
Db.users.remove (); All the data from the users are deleted.
Change: Update
db.users.update({username:"bbbbbb",{$set:{password:222222}}})//只修改username为bbbbbb里的passworddb.users.update({username:"aaaaaa"},{password:111111})//这条数据将被password替换掉db.users.update({},{$set:{password:22222}},{multi:true});3.0新版本修改所有passworddb.users.update({},{$set:{password:22222}},false,true);3.0一下旧版本修改所有password
Poor: Find
db.users.find().pretty();//查看所有被整理后的数据(即被美化)db.users.find({username:"aaaaaa"})//精确匹配db.users.find({age:{$gt:20}});//匹配年龄大于20的db.users.find({age:{$gt:20,$lt:30}})//匹配年龄大于20的,且小于30的db.users.find({age:{$gt:20},gender:"male"});//匹配年龄大于20的,且是男的db.users.find({$or:[age:{$gt:20},{gender:"male"}]});//匹配年龄大于20的,或则为男的db.students.find({name:{$regex:"^a",$option:"$i"}});//模糊查询,以a开头不论大小写db.students.find(0.limit(5).skip(1)//跳过第一条数据开始显示,总共显示5条数据db。students.find().sort({age:1})//按年龄从小到大排序,1代表升序,-1代表降序$lt:<$gt:>$gte:<=$lte:>=$ne:!=
MongoDB Database Basics