轉自:http://blog.csdn.net/xto/archive/2010/03/22/5403855.aspx
Bin\mongod run 啟動資料庫服務端。
bin\mongod.exe --dbpath d:\data\mongo 啟動資料庫服務端并且将資料庫目錄設定在該位址下。
run 直接啟動。例:./mongod run
--dbpath 指定特定存儲目錄啟動,若目錄不存在則建立。例:./mongod --dbpath /var/data/mongo
--port 指定端口啟動。例:./mongod --port 12345
bin\mongon.exe 啟動資料庫用戶端用指令行操作。
停止MONGO服務:
方法1:服務端停止,可使用Ctrl+C
方法2:在用戶端停止,可先連接配接用戶端
./mongo
并使用指令
db.shutdownerver()
然後退出用戶端
exit
啟動bin\mongodump.exe可以自動備份資料
bin/mongorestore.exe恢複一個mongo的dump備份資料
bin/mongoexport 導出一個資料表資料為(json,csv)格式
bin/mongoimportjson 将json格式的資料導入資料表表
bin/mongofiles gridfs檔案操作
關閉web伺服器作業系統之前必須先備份mongodb,然後關閉mongodb服務,在關閉或者重新啟動作業系統。
根據網上資料有人曾說直接關閉作業系統會導緻mongodb緩存資料沒有被寫入硬碟。
要經常性的觀察mongodb資料總存儲的大小,避免資料過大造成寫入困難導緻的資料丢失情況。
MongoDB.Driver0.8.1
該版本仍然處于dbug狀态,但好在代碼比較簡單,是以希望在此基礎上建構适合自身操作的驅動層。
Mongo mg = new Mongo(“localhost”,27087);//聲明資料庫操作類
bool result=mg.Connect();//打開連接配接
Database db = mg.getDB("db");//打開db資料庫
IMongoCollection col=db.GetCollection("table");//打開db資料庫中的table表
mg.Disconnect();//關閉連接配接
Document doc = new Document();//聲明資料類型
doc["name"] = "xto";//指派
doc["login"] = "test";//指派
col.Insert(doc);//插入資料
Document query=new Document();//聲明查詢條件對象
query.Add("id",1);//查詢條件對象指派
Document newdata = new Document();//聲明修改對象
newdata.Add("name","222");//修改對象指派
col.UpdateAll(newdata,query,true);//更新資料
ICursor cur = col.FindAll();//查詢指針
foreach (Document docx in cur.Documents)
{
Response.Write(docx["id"]+"</br>");
}
Document query = new Document();//聲明查詢條件對象
Document where = new Document();//聲明邏輯條件對象
where.Add("$gt",1);//邏輯條件對象指派;含義:>1
query.Add("id",where);
ICursor cur = col.Find(query).Skip(10).Limit(100);//從第10條記錄開始查詢每頁顯示100條
ICursor cur = col.Find(query);
Document index = new Document();//建立索引對象
index["id"] = 1;//索引對象指派
col.MetaData.CreateIndex(index,true);//建立索引
Document query = new Document();//建立删除條件對象
query.Add("id", 1);//條件對象指派
col.Delete(query,true);//删除滿足查詢條件的記錄