【MongoDB學習筆記4】MongoDB管理用戶端和建立資料庫

來源:互聯網
上載者:User

標籤:建立資料庫   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管理用戶端和建立資料庫

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.