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; } } }