首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

mongodb shell 实施 js 脚本

2013-03-13 
mongodb shell 执行 js 脚本利用mongodb执行js脚本的方法如下:./mongo 10.1.18.181:12000/xmail_db test.j

mongodb shell 执行 js 脚本

利用mongodb执行js脚本的方法如下:


./mongo 10.1.18.181:12000/xmail_db test.js

 

test.js 内容如下:

var cursor=db.getCollectionNames(); // 获取collection 名
for(i=0;i<cursor.length;i++)
{
 //printjson(cursor[i]);
 //var db=connect(db);
 var curU=cursor[i];
 if("system.indexes" == cursor[i] || "system.profile" == cursor[i])
 {
  print("find system");
 }
 else
 {  
  var whbC=db.getCollection(curU).count();
  var tmp=cursor[i]+"=="+whbC
  printjson(tmp);
  
  db.getCollection(cursor[i]).ensureIndex({"CreateTime":1});
 }
}

热点排行