• 【工作脚本】mongo operations



    Check Mongo Operate Logs


    db.getCollection('oplog.rs').find({'ns':{$in:['sxa.sxacc-organizations','sxa.devices']},'op':{$in:['u','i','d']},'wall':{$gt:new ISODate('2018-05-02T08:40:51')}})


    Update Mongo

    db.getCollection('sxacc-organizations').update({"_id" : "12605082"},{$set:{"updateSubscriberEnabled":"true"}});
    db.getCollection('sxacc-organizations').update({"_id" : "12605082"},{$set:{"updateDeviceEnabled":"true"}});
    db.getCollection('sxacc-organizations').update({"_id" : "12605082"},{$set:{"detachDeviceEnabled":"true"}});
    db.getCollection('sxacc-organizations').find({"_id" : "12605082"}); – check if the options are set successfully


    mongoexport -h localhost --db sxa --collection sxacc-devices --out sxacc-devices.json --query='{"orgId":"57550"}'
    mongoimport --host cdtsxacc01.calix.local --db=sxa --collection=sxacc_devices --file=sxacc-devices.json

    db.inventory.deleteOne( { status: "D" } )
    db.collection.deleteMany(
    <filter>,
    {
    writeConcern: <document>,
    collation: <document>
    }
    )


     mongo test --eval "printjson(db.getCollectionNames())"


    rs.initiate(
       {
          _id: "cmdctl",
          version: 1,
          members: [
             { _id: 0, host : "10.245.247.72:27017" },
             { _id: 1, host : "10.245.247.75:27017" },
             { _id: 2, host : "10.245.247.76:27017" }
          ]
       }
    )
    db.getCollection('sxacc-organizations').find({"_id" : "12605082"});
    db.getCollection('sxacc-organizations').update({"_id" : "12605082"},{$set:{"updateSubscriberEnabled":"true"}});
    db.getCollection('sxacc-organizations').update({"_id" : "12605082"},{$set:{"updateDeviceEnabled":"true"}});
    db.getCollection('sxacc-organizations').update({"_id" : "12605082"},{$set:{"detachDeviceEnabled":"true"}});
    db.getCollection('sxacc-organizations').find({"_id" : "12605082"}); – check if the options are set successfully
    db.getCollection('sxacc-devices').aggregate([
          {
            $group : {
               _id :"$orgId",
               count: { $sum: 1 }
            }
          },
          {$sort: { count: -1 } }
       ])
    var bulk = db['sxacc-subscriber-es'].initializeUnorderedBulkOp(); 
    db['sxa_organizations'].find({},{'orgId':1}).forEach(function (doc) 
    {
        bulk.insert({ 
            '_id': doc.orgId, 
            'status':'run' ,
            'start_time':Timestamp(1532422259, 0),
            "es_version" : "8038",
            "end_time" : Timestamp(1532422265, 0),
            "es_date" : Timestamp(1536879635, 0),
            "delete_index" : false
        });
    });
    bulk.execute();
    db.getCollection('sxacc-devices').aggregate([
    {$match:{"manufacturer" : "Calix","modelName" : 'GS2026E',"softwareVersion" : "3.2.0.17"}},
    {$group:{_id:'$orgId',count:{$sum:1}}}
    ])
     mongo mongodb://cdc-kylin:27017/cloud --eval 'printjson(db.serverStatus())'
    db['cloud_onboard_org_management'].update({org_id:'50'},{ $unset: { isMigrated: ""} })
    db.getCollection('sxafa_devices').aggregate(
       [
          {
            $group : {
               _id: "$flowType",
                count: { $sum: 1 }
            }
          }
       ]
    )
    mongoexport -d sxa -c sxa-subscribers --out sxa-subscribers.csv --files=_id,customId,name,orgId --type=csv  -q='{orgId:"117556"}'
    db.getCollection('sxa-subscriber-billing').getIndexes()
    db.getCollection('sxa-subscriber-billing').createIndex({"subscriberId": 1})
    # FULL root privilage
    use admin
    db.createUser({user: "root", pwd: "root", roles: ["root"] } )
     
    # Create admin user for sxa database
    use sxa
    db.createUser({user: "sxaAdmin", pwd: "sxaAdmin", roles: [ { role: "userAdmin", db: "sxa" }, { role: "readWrite", db: "sxa" }  ] } )
     
    # readonly user for sxa db
    use sxa
    db.createUser({user: "readonlysxa", pwd: "readonlysxa", roles: [ { role: "read", db:"sxa" } ] } )
     
    # readonly user for anything
    use admin
    db.createUser({user: "readonlyadmin", pwd: "readonlyadmin", roles: [ { role: "readAnyDatabase", db:"admin" } ] } )
      
      
    --
    Deprecated since version 3.0.0: db.collection.ensureIndex() is now an alias for db.collection.createIndex().
    Creates an index on the specified field if the index does not already exist.
    --
    db["sxa-subscribers"].ensureIndex({"orgId" : 1, "locations.devices" : 1},{"name" : "Devices", background: true})

    TODO

  • 相关阅读:
    linux环境下,使用Navicat连接mysql时,提示本地IP无法连接虚拟环境下的mysql解决方案
    数组-(Zero Sum Subarray)返回数组中和为某个数的子串数组
    hash、hashlib使用
    优先队列
    Jensen 不等式
    ML-集成学习:AdaBoost、Bagging、随机森林、Stacking(mlxtend)、GBDT、XGBoost、LightGBM、CatBoost原理推导及实现
    scipy.optimize优化器的各种使用
    RL-马尔科夫决策过程(MDP)-原理及实现
    ML-sklearn参数随机优化:GridSearchCV、RandomizedSearchCV、hyperopt
    5.matplotlib绘制-meshgrid区域图-可视化ML
  • 原文地址:https://www.cnblogs.com/tben/p/8989627.html
Copyright © 2020-2023  润新知