MongoDB 常用shell命令汇总
2017-01-13 16:17
447 查看
//指定用户名和密码连接到指定的MongoDB数据库
mongo 192.168.1.200:27017/admin -u user -p password
use youDbName
1.MongoDB 查询所有索引的命令:
2.MongoDB 创建索引的命令:
Unique Index:
注:
MongoDB无法创建指定的索引字段唯一索引(S)如果集合已经包含了将违反唯一性约束的数据指标。
MongoDB cannot create a unique index on the specified index field(s) if the collection already contains data that would violate the unique constraint for the index.
https://docs.mongodb.com/v3.0/tutorial/create-a-unique-index/
解决方法:
1.把集合数据导出(mongoexport)至csv文件备份。
2.清空集合数据。
3.创建 Unique Index
4.将 步骤1 备份的csv文件导入(mongoimport)集合。会自动过滤掉重复的数据。
效果:
3.MongoDB 模糊匹配查询:
4.MongoDB 查询结果按指定字段排序:
5.MongoDB update功能:
1.新增字段
2.更新字段值($set)
db.StrategyInfo.update({},{$set:{“test”:”股票池”}},false,true);
其中update()第3个参数,表示不存在的记录,是否插入,默认false,不插入。第4个参数,默认false只更新找到的第一条记录;true表示全部更新。
3.删除某一列($unset)
4.重命名列名($rename)
6.更改某一列的字段类型
1.查询某一列的字段类型($type)
2.更改(forEach)
db.calcgsdataflash_once.find().forEach(function(x){x.f2=String(x.f2);db.calcgsdataflash_once.save(x)})
7.修改用户密码:
db.changeUserPassword("root","123456")
mongo 192.168.1.200:27017/admin -u user -p password
use youDbName
1.MongoDB 查询所有索引的命令:
2.MongoDB 创建索引的命令:
Unique Index:
注:
MongoDB无法创建指定的索引字段唯一索引(S)如果集合已经包含了将违反唯一性约束的数据指标。
MongoDB cannot create a unique index on the specified index field(s) if the collection already contains data that would violate the unique constraint for the index.
https://docs.mongodb.com/v3.0/tutorial/create-a-unique-index/
解决方法:
1.把集合数据导出(mongoexport)至csv文件备份。
2.清空集合数据。
3.创建 Unique Index
4.将 步骤1 备份的csv文件导入(mongoimport)集合。会自动过滤掉重复的数据。
效果:
3.MongoDB 模糊匹配查询:
4.MongoDB 查询结果按指定字段排序:
5.MongoDB update功能:
1.新增字段
2.更新字段值($set)
db.StrategyInfo.update({},{$set:{“test”:”股票池”}},false,true);
其中update()第3个参数,表示不存在的记录,是否插入,默认false,不插入。第4个参数,默认false只更新找到的第一条记录;true表示全部更新。
3.删除某一列($unset)
4.重命名列名($rename)
6.更改某一列的字段类型
1.查询某一列的字段类型($type)
2.更改(forEach)
db.calcgsdataflash_once.find().forEach(function(x){x.f2=String(x.f2);db.calcgsdataflash_once.save(x)})
7.修改用户密码:
db.changeUserPassword("root","123456")
相关文章推荐
- MongoDB的学习与应用二:熟悉MongoDB Shell下常用命令
- MongoDB的学习与应用二:熟悉MongoDB Shell下常用命令
- MongoDB常用命令汇总之Collection聚集集合和用户相关。
- MongoDB常用命令汇总之基本聚合函数。
- MongoDB常用命令汇总之修改、添加、删除集合数据。
- 常用shell命令汇总
- 常用的shell命令汇总 Linux基础
- MongoDB常用命令汇总之语句块操作。
- 常用的shell命令汇总,夯实Linux基础
- MongoDB常用命令汇总之查看聚集集合基本信息。
- mongodb常用维护命令汇总
- 常用的shell命令汇总
- MongoDB Shell常用命令
- MongoDB常用命令汇总之数据库常用命令。
- 常用的Shell命令汇总
- MongoDB shell常用命令
- Linux常用的shell命令汇总
- 常用的shell命令汇总,夯实Linux基础
- MongoDB常用shell命令
- MongoDB常用命令汇总之索引。