標籤:建立資料庫 mongodb
MongoDB管理用戶端背後是一個JavaScript Shell,是一個完整的JavaScript解譯器,用”mongo”命令登入;
進入後進入預設的test資料庫,可以用db命令查看當前的所串連的資料庫:
[[email protected] ~]# mongo MongoDB shell version: 2.6.6 connecting to: test > db test >
輸入help來尋找可用的命令:
> help db.help() help on db methods db.mycoll.help() help on collection methods sh.help() harding helpers rs.help() replica set helpers help admin administrative help help connect connecting to a db help help keys key shortcuts help misc misc things to know help mr mapreduceshow dbs show database names show collections show collections in current database show users show users in current database show profile show most recent system.profile entries with time >= 1ms show logs show the accessible logger names show log [name] prints out the last segment of log in memory, ‘global‘ is default use <db_name> set current database db.foo.find() list objects in collection foo db.foo.find( { a : 1 } ) list objects in foo where a == 1 it result of the last line evaluated; use to further iterate DBQuery.shellBatchSize = x set default number of items to display on shell exit quit the mongo shell >
MongoDB沒有顯示的建立資料庫的命令和刪除的資料庫的命令,建立資料庫用use即可;
建立blog的資料庫:
> use blog switched to db blog
插入一個集合和文檔:
> db.post.insert({"geeting":3}); WriteResult({ "nInserted" : 1 })
查看建立的資料庫和集合:
> show dbs admin (empty) blog 0.078GB local 0.078GB > show collections post system.indexes
刪除資料庫
> db.dropDatabase(); { "dropped" : "blog", "ok" : 1 } > show dbs admin (empty) local 0.078GB
本文出自 “緣隨心愿” 部落格,請務必保留此出處http://281816327.blog.51cto.com/907015/1598286
【MongoDB學習筆記4】MongoDB管理用戶端和建立資料庫