更新列名
db.xx.update({}, {$rename : {"StoreId" : "MetaId"}}, false, true) 查询长度
db.getCollection("xx").find({$where:'this.StoreId.length>2'},{Name:0}) 查询总条数
db.getCollection("xx").find({}).count() 区间查询
db.getCollection("xx").find({'StoreId':1139,'CardNo':{'$gte':'90225001','$lte':'90295000'}}) 多个区间查询
db.getCollection("xx").find({ $or : [{ $and : [{"CardNo" : { $gte : "10000001" }}, {"CardNo" : { $lte : "10000003" }}] }, { $and : [{"CardNo" : { $gte : "10000006" }}, {"CardNo" : { $lte : "10000008" }}] }] }).limit(1000).skip(0) 排序 1 升序 -1降序
db.getCollection("xx").find().sort({"CreationTime":1}) db.xx.find({'PicId' : { $type : 16 }}).forEach(function(x) {x.PicId = String(x.PicId);db.Youzy_Stores_Experts.save(x); }) 添加一个字段. 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('xx').update({},{$rename:{"OId":'MetaId'}},false,true) 添加索引
db.test.createIndex({"username":1})
db.Youzy_Users_MobileAuthCodes.createIndex({"Code":1,"Mobile":1,"ExpiresTime":1},{"name":"MobileAuthCodes_Validate"}) group
db.getCollection("xx").aggregate([{$match:{"IsDeleted":false}},{$group : {_id : "$UserId", count : {$sum : 1}}},{$sort:{"count":-1}}]) --条件修改 update单个 updatemany 全部
db.getCollection('xx').update(
// query
{
"MenuKey" : 28
},
// update
{
$set:{"Url":"/tzy/choosebatch?type=3"}
},
false,
true
); 按照时间年月分组
db.xx.aggregate([
{$match: { CreateDate: { $gte: new Date('2018-01-01'), $lte: new Date('2019-07-31') } }} ,
{$group:{_id:{CreateDate:{year: { $year: "$CreateDate"},month: { $month: "$CreateDate" }}}, count: { $sum: 1 }}}
]) 分组
db.xx.aggregate([
{$match: { CreateDate: { $gte: new Date('2017-01-01'), $lte: new Date('2019-07-31') }}} ,
{ "$group": {
_id: { month: {
$dateToString: {
format: "%Y-%m",
date: "$CreateDate"
}
}
},
count: {
$sum: 1
}
}
},
{
"$project": {
"年月": "$_id.month",
"总数": "$count", }
}
])

最新文章

  1. char varchar nchar nvarcharar到底有多大区别
  2. const 和 readonly
  3. input标签内容改变的触发事件
  4. AIR ANE(本机扩展)使用中的一些问题(Android平台)
  5. 根本没有“JSON“对象这回事(读汤姆大叔博文记录)
  6. ASCII字符表
  7. Delphi版的完成端口控件
  8. Sublime Text3 配置markdown插件
  9. asp.net发布网站(转)
  10. android studio 快捷笔记
  11. C#现代代码风格指南
  12. Wannafly summer camp Day6 - D 区间权值
  13. Flink--3种分区方式
  14. input 随笔
  15. Python sys.stdout sys.stdin
  16. spark sql01
  17. [转]使用 ssh -R 穿透局域网访问内部服务器主机,反向代理 无人值守化
  18. 秒杀多线程第七篇 经典线程同步 互斥量Mutex
  19. jquery二维码生成插件_二维码生成器
  20. 滑动cell的时候执行动画效果

热门文章

  1. Spring boot 自定义注解标签记录系统访问日志
  2. ceph ---(ceph简介)
  3. 读取固定ResourceBundle
  4. JavaScript解构赋值
  5. 在 .NET Core Logging中使用 Trace和TraceSource
  6. 你必须知道的关于操作系统的N个概念!
  7. sentinel流量控制和熔断降级执行流程之源码分析
  8. linux(4)Linux 文件内容查看
  9. MySQL常用SQL语句1
  10. 牛客挑战赛33 C 艾伦的立体机动装置(几何)