MongoDB Database Basics

Source: Internet
Author: User

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

Related Article

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.