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

    更新列名

    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
    );
    
  • 相关阅读:
    java基础---多线程---volatile详解
    java基础---多线程---线程的几种状态及其转换,wait,notify,sleep,yield,join
    java基础---设计一个死锁
    count(1) and count(*),count(字段)区别及效率比较
    mysql之字段约束-第五篇
    mysql之数据表基本操作-第四篇
    mysql之数据类型-第三篇
    mysql之存储引擎-第二篇
    mysql之数据库操作-第一篇
    Redis详解
  • 原文地址:https://www.cnblogs.com/meowv/p/11310444.html
Copyright © 2011-2022 走看看