LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 09-10-2014, 10:14 AM   #1
robertjinx
Member
 
Registered: Oct 2007
Location: Prague, CZ
Distribution: RedHat / CentOS / Ubuntu / SUSE / Debian
Posts: 749

Rep: Reputation: 73
Question mongodb: Unauthorized to execute command


Hello, I've got an installation of mongodb 2.6.4 and a databases in it, but having some issues if I use auth = true:

Code:
<?php

 $m = new MongoClient("mongodb://user:pass@localhost/mydb");
 // $m = new MongoClient("mongodb://localhost:27017/mydb");
 $db = $m->selectDB("mydb");

 // coll is a collection
 $cursor = $db->execute("db.coll.count();");
 
 echo $cursor['retval'];
 
?>
Running this small PHP code ends up in error:

Code:
[conn2] Unauthorized not authorized on mydb to execute command { $eval: CodeWScope( db.coll.count();, {}), args: [] }
If I use auth = false in mongod.conf and switch to:

Code:
$m = new MongoClient("mongodb://localhost:27017/mydb");
The code works as expected.

I've ran db.createUser(...) and didn't return an error, but still nothing.

Also, if I use the command line command 'mongo' and do:

Code:
$ mongo
use mydb
db.auth("user", "pass")
db.coll.count()
All works.

Am I missing something? How could I fix this, add user 'user' to have proper access on db 'mydb' ?

Last edited by robertjinx; 09-10-2014 at 10:18 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I execute a shell command and put the result in command field? fran4tw Linux - General 9 08-08-2011 08:27 PM
Only execute 2nd command on successufl execution of 1st command kregec05 Linux - Newbie 3 08-19-2009 10:29 AM
Execute a command , reboot and then execute another command ganeshp@moris.org Linux - Newbie 3 12-03-2008 12:51 AM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM
Execute Command lawrencegoodman Linux - Newbie 2 10-23-2003 08:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 04:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration