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

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

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

查看所有标签

猜你喜欢:

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

Tagging

Tagging

Gene Smith / New Riders / 2007-12-27 / GBP 28.99

Tagging is fast becoming one of the primary ways people organize and manage digital information. Tagging complements traditional organizational tools like folders and search on users desktops as well ......一起来看看 《Tagging》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

SHA 加密
SHA 加密

SHA 加密工具

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具