MongoDB資料庫和集合的基本操作

來源:互聯網
上載者:User

標籤:概念   關係型資料庫   執行   insert   email   操作   擷取   sudo   資料   

非關係型資料庫

  • 命令區分大小寫;命令結束符為斷行符號(與MySQL不同之處)
mongodb配置
  • sudo service mongodb start
  • mongo
mongodb基本概念
    • 集合
      對應於關係型資料庫的的概念,建立集合:db.createCollections("<集合名>");刪除集合:db.<集合名>.drop();擷取所有集合:show collections
    • 文檔
      對應於關係型資料庫的記錄的概念,mongodb的文檔,是以類json的bson(json升級版)這種鬆散的資料結構表現的
      向集合中插入文檔
      1.使用insert()
      e.g.:db.<集合名>.insert([{name:"hello",email:"[email protected]"},{name:"world",email:"[email protected]"}])
      2.使用save()(注意與insert()區別,save()在插入資料時,如果集合不存在將自動建立集合)
      e.g.:db.<集合名>.save([{name:"hello",email:"[email protected]"},{name:"world",email:"[email protected]"}])
    • 資料庫
      1.建立資料庫:use <資料庫名>
      2.查看當前串連的資料庫:db
      3.查看所有資料庫:show dbs
      4.銷毀資料庫:切換到要銷毀的資料庫,然後執行db.dropDatabase()

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.