2015年2月27日 星期五

MongoDB 指令的使用

webber0928

顯示出目前有哪些資料庫
show dbs
新增一個資料庫friends
use friends
刪除現在正在使用的資料庫
db.dropDatabase()
顯示目前使用資料庫的名字
db.getName()
新增一個名字叫best的collection到friend這個資料庫,並寫入資料{name:”simon”,age:”25”}
db.best.insert({name:”simon”,age:”25”})
刪除best這個collection
db.best.drop()
顯示friend這個資料庫內的所有collections
show collections
db.getCollectionNames()
讀取best這個collection內的所有資料
db.best.find()
制定要搜尋best這個collection的範圍或是條件,以age來舉例,搜尋age值為25:
db.best.find({age:25})
在best這個collection內的name:simon後加入一個新的欄位,內容為phone:123
db.best.update({name:'simon'},{'$set':{phone:123}})
在best這個collection內刪除一個內容為phone:123的欄位
db.best.update({name:'simon'},{'$unset':{phone:123}})
將best這個collection內{name:’simon’}修改成{name:’yes’}
db.best.update({name:'simon'},{name:'yes'})
清空best這個collection 中的所有資料
db.best.remove()

By webber0928

一個小菜鳥工程師,對籃球還有夢想的男孩。

0 意見:

張貼留言

Coprights @ 2016, Blogger Templates Designed By Templateism | Distributed By Gooyaabi Templates