通过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});

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

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

查看所有标签

猜你喜欢:

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

Hacker's Delight

Hacker's Delight

Henry S. Warren Jr. / Addison-Wesley / 2002-7-27 / USD 59.99

A collection useful programming advice the author has collected over the years; small algorithms that make the programmer's task easier. * At long last, proven short-cuts to mastering difficult aspec......一起来看看 《Hacker's Delight》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器