???????????????????????????

????1    show dbs – List all databases.

????2    use db_name – Switches to db_name.

????3    show collections – List all tables in the current selected database.

????1    ???DBS -?г????е??????

????2    ???DB_NAME -????DB_NAME??

????3    ????? -?г??????????????е????б??

???????

??????????MongoDB?У??????SQL ???

????4. Insert A Record

?????????????????

?????????????????????db.tablename.save db.tablename.insert??{????}????{????}?? ????????????????????MongoDB???????????

> db.users.save({username:"google"??password:"google123"})
> db.users.find()
{ "_id" : ObjectId("504f45cd17f6c778042c3c07")?? "username" : "mkyong"?? "password" : "123456" }
{ "_id" : ObjectId("504f48ea17f6c778042c3c0a")?? "username" : "google"?? "password" : "google123" }

?????塢??????

???????????????????{???}??{$????{???}} db.tablename.update?? ??????????????У??????????????“mkyong”???????

> db.users.update({username:"mkyong"}??{$set:{password:"hello123"}})
> db.users.find()
{ "_id" : ObjectId("504f48ea17f6c778042c3c0a")?? "username" : "google"?? "password" : "google123" }
{ "_id" : ObjectId("504f45cd17f6c778042c3c07")?? "password" : "hello123"?? "username" : "mkyong" }

????6. Find Records

??????????????

??????????????????????db.tablename.find??{???}?? ??

????6.1?г??????м????“???”??

> db.users.find()
{ "_id" : ObjectId("504f48ea17f6c778042c3c0a")?? "username" : "google"?? "password" : "google123" }
{ "_id" : ObjectId("504f45cd17f6c778042c3c07")?? "password" : "hello123"?? "username" : "mkyong" }
>db.users.find????
{ “_id”??OBJECTID??“504f48ea17f6c778042c3c0a????“?????”??“???”??“????”??“google123” }
{ “_id”??OBJECTID??“504f45cd17f6c778042c3c07” ????“????“??“hello123” ??“?????”????“mkyong”}

????6.2???????????????????“google”

> db.users.find({username:"google"})
{ "_id" : ObjectId("504f48ea17f6c778042c3c0a")?? "username" : "google"?? "password" : "google123" }
>db.users.find??{???????“???”}??
{ “_id”??OBJECTID??“504f48ea17f6c778042c3c0a????“?????”??“???”??“????”??“google123” }

????6.3 Find records where username’s length is less than or equal to 2

????6.3????????????username?????С??????2

????6.4? Find records where username field is existed.

????6.4????????username??δ????????

????db.users.find({username:{$exists : true}})