通过shell脚本为mongodb建立索引

栏目: 数据库 · MongoDB · Linux · 发布时间: 7年前

内容简介:通过shell脚本为mongodb建立索引

通过 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
  1. ensureIndex.js的如下
db.user.ensureIndex({age:1});

db.user.ensureIndex({username:1});

db.user.ensureIndex({xxx:-1});

................

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Once Upon an Algorithm

Once Upon an Algorithm

Martin Erwig / MIT Press / 2017-9-8 / GBP 22.95

How Hansel and Gretel, Sherlock Holmes, the movie Groundhog Day, Harry Potter, and other familiar stories illustrate the concepts of computing. Picture a computer scientist, staring at a screen and......一起来看看 《Once Upon an Algorithm》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具