I'm building a simple Admin system for an Honours level University project.
Build on Codeigniter with MongoDB using the Alex Bible driver. I'm and trying to carry out a simple insert with hard coded values at the moment.
My Model
$username = "William";
$email = "Test";
$registerdata = array(
"username" => $username,
"email" => $email);
$collection = 'students';
$this->mongo_db->insert($collection, $registerdata);
Throwing the following errors:
PHP Error was encountered
Severity: Notice
Message: Undefined variable: insert
Filename: libraries/Mongo_db.php
Line Number: 456
And:
A PHP Error was encountered
Severity: Warning
Message: MongoCollection::insert(): expects parameter 1 to be an array or object, null given
Filename: libraries/Mongo_db.php
Line Number: 456
Any ideas?
It calls this function in the library if that helps any:
* Insert a new document into the passed collection
*
* @usage = $this->mongo_db->insert('foo', $data = array());
*/
public function insert($collection = "", $data = array()) {
if(empty($collection))
show_error("No Mongo collection selected to insert into", 500);
if(count($data) == 0 || !is_array($data))
show_error("Nothing to insert into Mongo collection or insert is not an array", 500);
try {
$this->db->{$collection}->insert($insert, array('safe' => TRUE));
if(isset($insert['_id']))
return($insert['_id']);
else
return(FALSE);
} catch(MongoCursorException $e) {
show_error("Insert of data into MongoDB failed: {$e->getMessage()}", 500);
}
}
insertmethod looks a bit odd. It references a variable called$insertbut I cannot see where it gets it from. Did you write that method? If so, maybe you meant$datainstead?