MongoDB Shell 命令
2024-09-03 22:31:36
更新列名
db.Stores.update({}, {$rename : {"StoreId" : "MetaId"}}, false, true)
查询长度
db.getCollection("Stores_Navigations").find({$where:'this.StoreId.length>2'},{Name:0})
查询总条数
db.getCollection("Stores_BusinessLogs").find({}).count()
区间查询
db.getCollection("Cards").find({'StoreId':1139,'CardNo':{'$gte':'90225001','$lte':'90295000'}})
排序 1升序 -1降序
db.getCollection("Stores_BusinessLogs").find().sort({"CreationTime":1})
更改字段类型
// 16代表int
db.Stores_Experts.find({'PicId' : { $type : 16 }}).forEach(function(x) {x.PicId = String(x.PicId);db.Stores_Experts.save(x); })
字段类型表
类型 | 对应数字 | 别名 |
---|---|---|
Double | 1 | double |
String | 2 | string |
Object | 3 | object |
Array | 4 | array |
Binary data | 5 | binData |
Undefined | 6 | undefined |
ObjectId | 7 | objectId |
Boolean | 8 | “bool” |
Date | 9 | “date” |
Null | 10 | “null” |
Regular Expression | 11 | “regex” |
DBPointer | 12 | “dbPointer” |
JavaScript | 13 | “javascript” |
Symbol | 14 | “symbol” |
JavaScript(with scope) | 15 | “javascriptWithScope” |
32-bit integer | 16 | “int” |
Timestamp | 17 | “timestamp” |
64-bit integer | 18 | “long” |
Min key | -1 | “minKey” |
Max key | 127 | “maxKey” |
- | - | - |
添加一个字段. table 代表表名 , 添加字段 content,字符串类型
db.table.update({}, {$set: {content:""}}, {multi: true})
删除一个字段
db.table.update({},{$unset:{content:""}},false, true)
清空数据
db.table.remove({})
查询指定列
db.news.find( {}, { id: 1, title: 1 } )
修改列表
db.getCollection('Orders_Scores').update({},{$rename:{"OId":'MetaId'}},false,true)
添加索引
db.test.createIndex({"username":1})
db.Users_MobileAuthCodes.createIndex({"Code":1,"Mobile":1,"ExpiresTime":1},{"name":"MobileAuthCodes_Validate"})
group分组
db.getCollection("Users_GaoKaoScores").aggregate([{$match:{"IsDeleted":false}},{$group : {_id : "$UserId", count : {$sum : 1}}},{$sort:{"count":-1}}])
按条件修改update
db.getCollection('Stores_Navigations').update(
// query
{
"MenuKey" : 28
},
// update
{
$set:{"Url":"/tzy/choosebatch?type=3"}
},
false,
true
);
最新文章
- audacity开源VS2013环境搭建
- final review 报告
- BZOJ 1054 广搜
- (转)JAVA AJAX教程第一章-初始AJAX
- C# 中的可变参数方法(VarArgs)
- 以后坚持用java
- [io PWA] Great libraries and tools for great Progressive Web Apps
- [OpenNebula]中间件訪问驱动程序
- IE input X 去掉文本框的叉叉和密码输入框的眼睛图标
- SSM整合中遇到的不能扫描注解的bug
- hdu 4885 (n^2*log(n)推断三点共线建图)+最短路
- SQL注入渗透实战
- Redis数据结构之简单动态字符串SDS
- 连接SQLsever数据库在C#中不能操作的问题
- selenium-java,selenium安装配置
- python自动化运维笔记1 —— 系统性能信息模块psutil
- Bmob后端云使用步骤
- leetcode笔记:3Sum Closest
- NYOJ 迷宫寻宝(一)
- MyEclipse配置默认自带的XML代码格式化