内容简介:通过shell脚本为mongodb建立索引
1.mongodb建立索引的命令为
db.collections.ensureIndex({xx:1})
我们为表user建立字段为age的索引
db.user.ensureIndex({age:1})
1 这里代表升序,-1代表降序
2.1个表1个索引,我们可以通过手动输入,如果在服务器上有多张表,多个索引,这种在终端敲的方法肯定不行,因为容易出错,检查出错会浪费很多的时间,因此通过执行shell文件
3.建立shell文件.名称为 ensureIndex.sh
cd /usr/src/mongodb-linux-x86_64-2.0.1/bin
./mongo 192.168.1.250/你的数据库名字 ensureIndex.js
- ensureIndex.js的如下
db.user.ensureIndex({age:1});
db.user.ensureIndex({username:1});
db.user.ensureIndex({xxx:-1});
................
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 如何使用python脚本检查elasticsearch中是否存在索引并对其执行异常处理?
- MySQL索引使用说明(单列索引和多列索引)
- Elasticsearch索引的基本操作(3)-索引的滚动索引
- Coreseek 增量索引模拟实时索引
- Coreseek 增量索引模拟实时索引
- MySQL高效索引之覆盖索引
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。