Re: Get list of uses from system.users

43 views
Skip to first unread message

Stephen Lee

unread,
Nov 14, 2012, 4:24:21 PM11/14/12
to mongod...@googlegroups.com
Andre,

I created a simple Mongo instance on my machine, created a "super" user in the admin database, and created a "hello" user (eg. b.getSiblingDB("testone").addUser("hello","world")) in the testone database.

    coll = my_db.collection( 'system.users' )
    coll.find.each { |doc| puts "user: #{doc[ 'user' ]}, readOnly: #{doc[ 'readOnly' ]}" }

I do see the testone.system.users collection and was successful in outputting a list of users.  Could you try my sample code?  What errors do you see?

What version of the Ruby driver and MongoDB are you using?

-Stephen

On Thursday, November 1, 2012 3:04:28 PM UTC-4, Andre Pollard wrote:
i have authentication enabled 
i am using a ruby script

i can connect to the admin db
switch to my testone db
list the collections where i see the system.users collection
but can't get the users after that

code
============
require 'rubygems'
require 'mongo'

conn = Mongo::Connection.new("avenger", 10001 )
puts "connection:#{conn.inspect}"

conn.db('admin').authenticate("super","superpassword")
puts "connection:#{conn.inspect}"

master_status = conn.db('admin').command({'isMaster'=>1})
puts "master_status:#{master_status}"


if master_status['ismaster'] 

my_db = conn.db('testone')
puts "switch to my_db: #{my_db.inspect}"

my_db.collection_names
puts "my_db collections :#{my_db.collection_names.inspect}"  #get ["system.indexes", "testone_collection", "system.users"]
# how do i run the equivalent of db.system.users.find(), tried several things but to no luck
else
  puts "Not master"
end
Reply all
Reply to author
Forward
0 new messages