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

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

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

查看所有标签

猜你喜欢:

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

High Performance JavaScript

High Performance JavaScript

Nicholas C. Zakas / O'Reilly Media / 2010-4-2 / USD 34.99

If you're like most developers, you rely heavily on JavaScript to build interactive and quick-responding web applications. The problem is that all of those lines of JavaScript code can slow down your ......一起来看看 《High Performance JavaScript》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

SHA 加密
SHA 加密

SHA 加密工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试