MongoDb query works in shell, and does not work in PHP [closed]

0

I need help in querying the mongoDB database, in the shell I can perform the search normally, however, on the site, I get the error 'not authorized for query on'. I use the mLab service for database.

I'm using the same user in the shell and in PHP, the version of my database is 3.4.10 and the codeigniter library version is 1.0.

Shell Connection:

mongo ds249757.mlab.com:49757/tx5 -u user -p pass

Connection codeigniter

<?php

//mongodb host
$config['default']['mongo_hostbase'] = 'ds249757.mlab.com:49757';
//mongodb name

$config['default']['mongo_database'] = 'tx5';
//mongodb username - by default, it is empty
$config['default']['mongo_username'] = 'user';
//mongodb password - by default, it is empty
$config['default']['mongo_password'] = 'pass';      
$config['default']['mongo_persist']  = FALSE;
$config['default']['mongo_persist_key']  = 'ci_persist';
$config['default']['mongo_replica_set']  = FALSE;
$config['default']['mongo_query_safety'] = 'safe';
$config['default']['mongo_suppress_connect_error'] = FALSE;
$config['default']['mongo_host_db_flag']   = FALSE; 

?>

Query no codeigniter

<?php 
        $this->load->library('mongo_db');
        $category = $this->mongo_db->db->admin->find();
       foreach ($category  as $cat)
       {
        $name=$cat['username'];
       $passwd=$cat['password'];
       }
         ?>

Screens

<p>Permissões Usuário
<a href="https://i.stack.imgur.com/xU7pY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xU7pY.png"alt="enter image description here"></a></p>

<p>Query no Shell
<a href="https://i.stack.imgur.com/FgdyN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FgdyN.png"alt="enter image description here"></a></p>

<p>Query no codeigniter
<a href="https://i.stack.imgur.com/43E4U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/43E4U.png"alt="enter image description here"></a></p>

<p>Banco de dados MLAB
<a href="https://i.stack.imgur.com/OEp3O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OEp3O.png"alt="enter image description here"></a></p>
    
asked by anonymous 10.01.2018 / 13:51

1 answer

2

The problem was in the codeigniter library, it was not sending the user and password to connect to the server.

    
11.01.2018 / 14:37