MongoDB 是一款NoSql資料庫,沒有固定的模式,即同一個集合中的不同文檔結構可以不同,如:第一條記錄{name:”xiaoming”},第二條記錄:{name:”xiaoli”,age:15},這在關係型資料庫中是無法實現的。對於MongoDB,其中:collections即集合相當於關係型 ...
MongoDB 是一款NoSql資料庫,沒有固定的模式,即同一個集合中的不同文檔結構可以不同,如:第一條記錄{name:”xiaoming”},第二條記錄:{name:”xiaoli”,age:15},這在關係型資料庫中是無法實現的。對於MongoDB,其中:collections即集合相當於關係型資料庫的表,document文檔相當於關係型資料庫中的行。因此也就是說,MongoDB中的表中存儲的數據可以不規定類型等。下麵看一下MongoDB自帶shell客戶端的一些基本操作。
先來看一下,如何打開客戶端shell。 如果將MongoDB配置進系統的環境變數,則直接在命令行輸入即可: 1、shell登陸mongodb客戶端 若沒有配置環境變數,則直接到安裝目錄下去登陸 如我的安裝目錄是在/home/lutong/mongodb/bin/mongo MongoDB 是一款NoSql資料庫,沒有固定的模式,即同一個集合中的不同文檔結構可以不同,如:第一條記錄{name:”xiaoming”},第二條記錄:{name:”xiaoli”,age:15},這在關係型資料庫中是無法實現的。對於MongoDB,其中:collections即集合相當於關係型資料庫的表,document文檔相當於關係型資料庫中的行。因此也就是說,MongoDB中的表中存儲的數據可以不規定類型等。下麵看一下MongoDB自帶shell客戶端的一些基本操作。
先來看一下,如何打開客戶端shell。 註意:先要開啟服務哦,不會的童鞋參見這篇文章(linux下登陸MongoDB的兩種方式) 如果將MongoDB配置進系統的環境變數,則直接在命令行輸入即可: 1、shell登陸mongodb客戶端 若沒有配置環境變數,則直接到安裝目錄下去登陸 如我的安裝目錄是在/home/lutong/mongodb/bin/mongo

shell基本操作 2、查看所有資料庫 show dbs

3、創建一個資料庫 use [database] (註:若database不存在,則會創建一個,此時若不做任何操作直接退出,則MongoDB會刪除該資料庫)

4、給指定資料庫添加文檔記錄 db.[collectionName].insert({...})



7、刪除集合中的數據 db.[collection].remove({刪除條件})

8、刪除資料庫中的集合 db.[collection].drop()

9、刪除資料庫 db.dropDatabase()
