Skip to content

Instantly share code, notes, and snippets.

@jbrechtel
Created May 23, 2014 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrechtel/603475bc8b03e020203c to your computer and use it in GitHub Desktop.
Save jbrechtel/603475bc8b03e020203c to your computer and use it in GitHub Desktop.
auth?!
#mongo 2.4 running with --auth
require 'mongo'
require 'json'
client = Mongo::MongoClient.new('localhost', 27017)
admin = { user: 'admin', pwd: 'password', roles: ['readWriteAnyDatabase', 'userAdminAnyDatabase', 'clusterAdmin'] }
user = { user: 'app', pwd: 'password', roles: ['readWrite'] }
client['admin'].eval("db.addUser(#{admin.to_json})")
client['admin'].authenticate('admin', 'password')
client['appDb'].eval("db.addUser(#{user.to_json})") #Database command '$eval' failed: unauthorized (Mongo::OperationFailure)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment