Saturday, August 4, 2018

User Management commands


user add:


db.auth({"user”:”dbtest”,”pwd”:”ChangeMe”});

db.createUser(
   {
     user: "dbtest",
     pwd: "ChangeMe",
     "roles" : [
{
"role" : "clusterAdmin",
"db" : "admin"
},
{
"role" : "appDBARole",
"db" : "admin"
}
]
  }
)


db.createUser(
   {
     user: "dbtest",
     pwd: "ChangeMe",
     "roles" : [
{
"role" : "clusterMonitor”,
"db" : "admin"
}
]
  }
)


use $external
db.createUser({
"user" : "abc",
"roles" : [
{
"role" : "publicRole",
"db" : "admin"
},
{
"role" : "appReadRole",
"db" : "pdb01"
}
]
})


db.system.users.find({"db":"$external",_id:"$external.dm_admin"})


db.runCommand({ usersInfo: { user: “dm_admin”,db:"admin" } })

Current user:

db.runCommand({connectionStatus : 1})


Grant additional Role to user


show users or
db.system.users.find({user:”dpxabc"})

prod => db.grantRolesToUser( "dm_admin", ["clusterAdmin"])

non-prod

db.grantRolesToUser( "dm_read", ["clusterMonitor"])
db.grantRolesToUser( "dm_write", ["clusterMonitor"])
db.grantRolesToUser( "dm_read", [{ role: "read", db: "local"}])

db.grantRolesToUser( "dm_write", [{ role: "read", db: "local"}])

Friday, August 3, 2018

Activity and Lock Monitoring


db.currentOp()


Long Running queries:
=================
query active on particular db and more than x amount of seconds

db.currentOp(    {      "active" : true,      "secs_running" : { "$gt" : 30000 },      "ns" : /^qptdb01\./    } )

Active Indexing Operations
=====================

db.currentOp(     {       $or: [         { op: "command", "query.createIndexes": { $exists: true } },         { op: "none", ns: /\.system\.indexes\b/ }       ]     } )

Write waiting for lock
================

db.currentOp(    {      "waitingForLock" : true,      $or: [         { "op" : { "$in" : [ "insert", "update", "remove" ] } },         { "query.findandmodify": { $exists: true } }     ]    } )

All the active transactions waiting to complete
===================================
db.currentOp(    {      "active" : true,      "numYields" : 0,      "waitingForLock" : false    } )