更新列名

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
);

最新文章

  1. audacity开源VS2013环境搭建
  2. final review 报告
  3. BZOJ 1054 广搜
  4. (转)JAVA AJAX教程第一章-初始AJAX
  5. C# 中的可变参数方法(VarArgs)
  6. 以后坚持用java
  7. [io PWA] Great libraries and tools for great Progressive Web Apps
  8. [OpenNebula]中间件訪问驱动程序
  9. IE input X 去掉文本框的叉叉和密码输入框的眼睛图标
  10. SSM整合中遇到的不能扫描注解的bug
  11. hdu 4885 (n^2*log(n)推断三点共线建图)+最短路
  12. SQL注入渗透实战
  13. Redis数据结构之简单动态字符串SDS
  14. 连接SQLsever数据库在C#中不能操作的问题
  15. selenium-java,selenium安装配置
  16. python自动化运维笔记1 —— 系统性能信息模块psutil
  17. Bmob后端云使用步骤
  18. leetcode笔记:3Sum Closest
  19. NYOJ 迷宫寻宝(一)
  20. MyEclipse配置默认自带的XML代码格式化

热门文章

  1. 干货最新版 Spring Boot2.1.5 教程+案例合集
  2. Linq 将两个查询结果合称为一个
  3. Java设计模式原型模式
  4. 【翻译】tus----一个可续传文件上传的开放协议
  5. ORA-03113: 通信通道的文件结束解决方法一例
  6. PHP中,json汉字编码
  7. ObjC: 委托模式
  8. 周黑鸭借力MES,推进智能生产
  9. 易语言 MD5生成
  10. App过大