Chapter2: MongoDB

This section contain the following items:

  • 1.What is MongoDB?

  • 2.build MongoDB environment on Ubuntu (14.04)

  • 3.MongoDB debug message

  • 4.Backup and Restore

  • 5.Use mongoDb by using python

  • 6.MongoDB的基本操作

1.What is MongoDB?

2.build MongoDB environment on Ubuntu (14.04)

  1)echo “deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" | sudo tee /etc/apt/sources.list.d/mongo.list:

  建立/etc/apt/sources.list.d/mongo.list,並寫入deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen(作為操作的一部分,APT使用一個檔案列出可獲得套裝軟體的鏡像站台位址件- /etc/apt/sources.list.d

檔案中的各項資訊通常按如下格式列出:deb http://host/debian distribution section1 section2 section3)

  2)sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10:

    如果公鑰已經上傳到Key Server,可以使用下列指令下載公鑰:
      gpg --keyserver hkp://wwwkeys.us.pgp.net --recv-keys <金鑰指紋>

  3)sudo apt-get update:

    進行伺服器與用戶端的套件表頭清單更新, 在 apt-get update 後,再使用 apt-get dist-upgrade 這樣就能夠將整個系統升級

  4)sudo apt-get install mongodb-10gen

  5)ps -ef | grep mongo:

    確定 mongodb已在執行

  6)ls -ls /usr/bin | grep mongo

  7)ls -ls /etc/init.d | grep mongo

  8)sudo service mogodb start, sudo service mogodb stop, sudo service mogodb restart

3.MongoDB debug message

4.Backup and Restore

5.Use mongoDb by using python

6.MongoDB的基本操作

  • 與SQL的名詞對照

  • 與SQL指令的對照表

MongoDB

My SQL

新增

db.collection.find(條件)

select

修改

db.collection.insert(document)

insert

刪除

db.collection.update( criteria, objNew, upsert, multi )

update

查詢

db.collection.remove()

delete

Last updated

Was this helpful?