1

I'm using Codeigniter MVC.I installed MongoDB but it doesn't work.

I'm getting this error;

Unable to connect to MongoDB: Failed to connect to: localhost:27017: SASL Authentication failed on database 'teknikserviscim': Authentication failed.

The config file is like this;

$config['mongo_db']['active'] = 'newdb';    
$config['mongo_db']['newdb']['hostname'] = 'localhost';    
$config['mongo_db']['newdb']['port']     = '27017';    
$config['mongo_db']['newdb']['username'] = 'superuser';    
$config['mongo_db']['newdb']['password'] = '12345678';    
$config['mongo_db']['newdb']['database'] = 'teknikserviscim';    
$config['mongo_db']['newdb']['db_debug'] = TRUE;    
$config['mongo_db']['newdb']['write_concerns'] = (int)1;    
$config['mongo_db']['newdb']['journal'] = TRUE;    
$config['mongo_db']['newdb']['read_preference'] = NULL;
$config['mongo_db']['newdb']['read_preference_tags'] = NULL;


class PanelHesap extends CI_Model {

public function __construct()
{
    parent::__construct();
    $this->load->library('mongo_db', array('activate'=>'newdb'),'mongo_db2');       
}

Well. What Is The Problem ? Thanx.

2
  • Error you have got led to this solution. Try if helps. Commented Oct 16, 2016 at 12:59
  • I deleted I'm not using thanks to everyone. Commented Oct 16, 2016 at 14:23

1 Answer 1

1

Your DB connection should be

$config['mongo_db']['active'] = 'default';
$config['mongo_db']['default']['no_auth'] = FALSE;
$config['mongo_db']['default']['hostname'] = 'localhost';
$config['mongo_db']['default']['port'] = '27017';
$config['mongo_db']['default']['username'] = 'admin';
$config['mongo_db']['default']['password'] = '123456';
$config['mongo_db']['default']['database'] = 'mydatabase';
$config['mongo_db']['default']['db_debug'] = TRUE;
$config['mongo_db']['default']['return_as'] = 'array';
$config['mongo_db']['default']['write_concerns'] = (int)1;
$config['mongo_db']['default']['journal'] = TRUE;
$config['mongo_db']['default']['read_preference'] = NULL;
$config['mongo_db']['default']['read_preference_tags'] = NULL;
$config['mongo_db']['default']['no_auth'] = FALSE;

and in application/libraries add this library

GIT Hub

and in autoload.php

$autoload['libraries'] = array('Mongo_db');

And insert, update, delete example

Check this

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.