zoukankan      html  css  js  c++  java
  • 【工作脚本】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

  • 相关阅读:
    URAL 2046 A
    URAL 2056 Scholarship 水题
    Codeforces Gym 100286I iSharp 水题
    Codeforces Gym H. Hell on the Markets 贪心
    Codeforces Gym 100286G Giant Screen 水题
    Codeforces Gym 100286B Blind Walk DFS
    Codeforces Gym 100286F Problem F. Fibonacci System 数位DP
    Codeforces Gym 100286A. Aerodynamics 计算几何 求二维凸包面积
    Codeforces Gym 100418K Cards 暴力打表
    Codeforces Gym 100418J Lucky tickets 数位DP
  • 原文地址:https://www.cnblogs.com/tben/p/8989627.html
Copyright © 2011-2022 走看看