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

  • 相关阅读:
    阿里云CentOS 7无外网IP的ECS访问外网(配置网关服务器)
    CentOS 7配置成网关服务器
    Mac/Ubuntu下的数据建模工具PDMan,替代PowerDesigner
    Docker卸载高版本重装低版本后启动提示:driver not supported
    Redis连接出现Error: Connection reset by peer的问题是由于使用Redis的安全模式
    Mac流量监控/硬盘监控小工具
    CentOS 7创建自定义KVM模板(现有KVM迁移到另外一台机)
    vi显示行号
    阿里云与微软云的对照表
    CentOS下安装Jenkins(Docker/war/tomcat/java -jar)
  • 原文地址:https://www.cnblogs.com/tben/p/8989627.html
Copyright © 2011-2022 走看看