zoukankan      html  css  js  c++  java
  • MongoDB shell 命令

       

    更新列名
    db.Youzy_Stores.update({}, {$rename : {"StoreId" : "MetaId"}}, false, true)
    
    查询长度
    db.getCollection("Youzy_Stores_Navigations").find({$where:'this.StoreId.length>2'},{Name:0})
    
    查询总条数
    db.getCollection("Youzy_Stores_BusinessLogs").find({}).count()
    
    区间查询
    db.getCollection("Youzy_Cards").find({'StoreId':1139,'CardNo':{'$gte':'90225001','$lte':'90295000'}})
    
    多个区间查询
    db.getCollection("Youzy_Cards").find({ $or : [{ $and : [{"CardNo" : { $gte : "10000001" }}, {"CardNo" : { $lte : "10000003" }}] }, { $and : [{"CardNo" : { $gte : "10000006" }}, {"CardNo" : { $lte : "10000008" }}] }] }).limit(1000).skip(0) 
    
    排序 1 升序  -1降序
    db.getCollection("Youzy_Stores_BusinessLogs").find().sort({"CreationTime":1})
    
    db.Youzy_Stores_Experts.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('Youzy_Orders_Scores').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("Youzy_Users_GaoKaoScores").aggregate([{$match:{"IsDeleted":false}},{$group : {_id : "$UserId", count : {$sum : 1}}},{$sort:{"count":-1}}]) --条件修改
    
    //update
    db.getCollection('Youzy_Stores_Navigations').update( 
        // query 
        {
            "MenuKey" : 28
        }, 
        // update 
        {
            $set:{"Url":"/tzy/choosebatch?type=3"}
        },
        false,  
        true     
    );
      
    按照时间年月分组
    db.Youzy_Users.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.Youzy_Users.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",
                   
                }
            }
    ]) 
    
  • 相关阅读:
    bzoj3295: [Cqoi2011]动态逆序对
    bzoj3262: 陌上花开
    bzoj1176: [Balkan2007]Mokia
    bzoj1935: [Shoi2007]Tree 园丁的烦恼
    [APIO / CTSC2007]数据备份 --- 贪心
    [APIO2007]风铃 --- 贪心
    [NOI2015]寿司晚宴 --- 状压DP
    [NOI2007]货币兑换 --- DP + 斜率优化(CDQ分治)
    [NOI2009]诗人小G --- DP + 决策单调性
    [HNOI2008]玩具装箱TOY --- DP + 斜率优化 / 决策单调性
  • 原文地址:https://www.cnblogs.com/panjuan/p/11697905.html
Copyright © 2011-2022 走看看