生活 + 筆記

5.16.2013

MongoDB Shell


在 mongo DB 可直接執行 mogo shell,或是用 shell method 來下 query

1. 執行 mongodb
$ mongo

2. 列出目前所使用的 db
$ db ( default 的 db 是 test )

3. 轉換到其他 db
$ use
* 新增一個 db 的時候可直接用 use  
4. 列出所有 db
$ show dbs

5. 列出此 db 所有的 collection
$ show collections

6. 離開 mongodb
$ quit() or 'control+c'

7. select
$ db.collection.find()
// query 目前 db 的某個 collection
8. insert 新增 collection
$ db.collection.insert() or db.collection.save()

9. update 更新 collection
$ db.collection.update() or db.collection.save()
* save = insert + update
10. 刪除 collection
$ db.collection.remove()

add 'user' db, new 'account' collection and update the collection


更詳細的 shell method 用法

沒有留言:

張貼留言