<shell>MongoDB神奇命令,常用常用非常实用!
2017-03-07 19:14
701 查看
使用robomongo工具
1.sort
对某个字段进行排序:db.getCollection('content').find({}).sort({"time":-1})
-1:代表倒叙;
1:代表正序;
2.模糊查询
对某个字段的value进行模糊查询:
db.getCollection('content').find({"user":{$regex:'小名''}})
或:
db.getCollection('content').find({"user":/小名/})
$options:"$i" ,不区分大小写
mongodbApi写法如下:
Pattern pattern = Pattern.compile("^.*" +
名 + ".*$" , Pattern.CASE_INSENSITIVE);
如果字段名称为name,则查询写法如下:
new BasicDBObject().append("name", pattern);
3、Distinct
db.runCommand({distinct:"person",key:"country"}).values;
4.查看某个字段的type为long
db.getCollection('content').find({"times":{$type:"long"}})
5.查看存在某个字段的数据
db.getCollection('content').find({"timestamp":{$exists:true}})
true:存在
false:不存在
6.删除某个字段
将users这个字段删除
db.getCollection('content').update({},{"$unset":{'users':1}},false,true)
7.字段重命名
将’abc‘字段名改为’def‘
db.test.update({}, {$rename : {"abc" : "def"}}, false, true)
语法:
{$rename: { <old name1>: <new name1>, <old name2>: <new name2>, ... } }
更新数据:
db.getCollection('user').update({},{$set:{"age":14}},false,true)
更新多条数据用“,”隔开。
相关文章推荐
- 常用shell命令总结,非常实用
- MongoDB的学习与应用二:熟悉MongoDB Shell下常用命令
- Linux 常用命令的使用(非常实用)
- <shell> mongodb查看某个字段的数据类型
- <Linux>压缩解压常用命令
- 实用and常用shell命令汇编
- <Linux> Linux下一些常用命令(个人记录)
- <转>13个实用的Linux find命令示例
- mongodb shell常用命令,同样适合于NoSqlL Manager for Mongodb 中shell
- <Linux>CentOS常用命令
- <转载>DB2常用命令
- linux不常用但非常实用的命令
- <02>Linux基本命令及常用命令
- 非常实用的DOS常用命令
- <二>树莓派常用命令
- MongoDB shell常用命令
- MongoDB Shell常用命令
- MongoDB mongo shell,常用的操作命令,GUI客户端
- MongoDB常用shell命令
- << 转载>>Shell一些强大的命令