Skip to content

Instantly share code, notes, and snippets.

@realdubb
Last active June 1, 2018 21:35
Show Gist options
  • Save realdubb/805b3be22d581cd0c0bd1d85cc3e323e to your computer and use it in GitHub Desktop.
Save realdubb/805b3be22d581cd0c0bd1d85cc3e323e to your computer and use it in GitHub Desktop.
mongodb queries

Using database with hyphen

db = db.getSiblingDB("dbname-w-hyphen")
db.dropUser("admin")

Get user

use db
db.getUser("root")

Get all users

db.getCollection('system.users').find({})

Create user who can readWriteAnyDatabase

db.createUser({ user: "<username>", pwd: "<password>", roles: [ { db: "admin", role: "readWriteAnyDatabase" }] })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment