Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB\Driver\Exception\InvalidArgumentException in codeigniter 3.x

After migrating a project in CI 2.x to 3.x the following error is shown where i used mongo db, this works fine in codeigniter version 2,

Message: Failed to parse MongoDB URI: 'mongodb://'. Invalid host string in URI.

Db Configuration

// Generally will be localhost if you're querying from the machine that Mongo is installed on
$config['mongo_host'] = "localhost";
//$config['mongo_host'] = "xxxxxxxxx.compute.amazonaws.com";

// Generally will be 27017 unless you've configured Mongo otherwise
$config['mongo_port'] = 27017;

// The database you want to work from (required)
$config['mongo_db'] = "test_p1";

// Leave blank if Mongo is not running in auth mode
$config['mongo_user'] = "";
$config['mongo_pass'] = "";

// Persistant connections
$config['mongo_persist'] = TRUE;
$config['mongo_persist_key'] = 'ci_mongo_persist';

// Get results as an object instead of an array
$config['mongo_return'] = 'array'; // Set to object

// When you run an insert/update/delete how sure do you want to be that the database has received the query?
// safe = the database has receieved and executed the query
// fysnc = as above + the change has been committed to harddisk <- NOTE: will introduce a performance penalty
$config['mongo_query_safety'] = 'safe';

// Supress connection error password display
$config['mongo_supress_connect_error'] = TRUE;

// If you are having problems connecting try changing this to TRUE
$config['host_db_flag'] = FALSE;
like image 964
ASWIN TK Avatar asked Nov 07 '22 05:11

ASWIN TK


1 Answers

you may forget to set up db in your local machine.

like image 174
Aswin TK Avatar answered Nov 15 '22 05:11

Aswin TK