標籤:style blog class code java ext
try{ INIT_PLUG I_MongoDB* i = NEW(MongoDB); /*【注】 若自訂錯誤訊息的數組長度必需指定為MAX_ERROR_SIZE*/ //char errmsg[MAX_ERROR_SIZE]={0};//方式一 extern char mongoErrMsg[];//方式二 char *errmsg=mongoErrMsg; char host[]="192.168.1.105";//192.168.1.21//115.28.161.80 char port[]="27017"; //串連伺服器 if(! i->Connect(host,port,errmsg)) { cout<<"Error:"<<errmsg<<endl; return 0; } else cout<<"Connect successfully!"<<endl; //以超級管理員權限登陸,admin資料庫是特權庫,可以登陸到任意庫,只要SuperAdmin是非唯讀即可進行任何操作。 //許可權驗證 if(! i->Auth("DBCenter","DBCenter_admin","123456",errmsg)) cout<<"Error:"<<errmsg<<endl; else cout<<"Auth successfully!"<<endl; const char* ns="DBCenter.T_ActorInfo";//定義庫資料表空間 char conJson[20]; char setJson[30]; bool ret; int interval = 1000; int mapID = 1001; for (int x = 1001; x <= 6000; x++) { sprintf_s(conJson, "{_id:%d}", x); sprintf_s(setJson, "{$set:{‘map‘:%d}}", mapID); ret=i->UpdataData(ns, conJson, setJson,errmsg,true,true); if(!ret) { cout<<errmsg<<endl; return false; } if (x % interval == 0) { if (++mapID == 1006) { mapID = 1001; } } }