ichikaway / mongoDB-Datasource

Old and Historical repository. Please use new repository at: http://github.com/ichikaway/cakephp-mongodb
85 stars 28 forks source link

MongoCollection::insert() must be of the type array #10

Open fredrikpaulin opened 11 years ago

fredrikpaulin commented 11 years ago

Warning (4096): Argument 2 passed to MongoCollection::insert() must be of the type array, boolean given, called in /var/www/lib/Cake/Model/Model.php on line 1734 and defined [APP/Plugin/Mongodb/Model/Datasource/MongodbSource.php, line 465] Notice (8): Undefined index: _id [APP/Plugin/Mongodb/Model/Datasource/MongodbSource.php, line 476] Notice (8): Undefined index: _id [APP/Plugin/Mongodb/Model/Datasource/MongodbSource.php, line 477]

And the code: $note = array( 'type' => 'connection', 'message' => 'connected to', 'user' => $us, 'subject' => $id
);

    if($this->Notification->save($note)){
        $this->log('added note', 'debug');
    }
    else{
        $this->log('failed to add note', 'debug');
    }

Any ideas?

dizyart commented 11 years ago

You are probably using PHP5.4, which triggers strict warnings if function arguments are of the wrong type.

I fixed this by editing the MongodbSource.php, near line 466, you will find a:

->insert($data, true);

change it to

->insert($data, array());

dizyart commented 11 years ago

Btw, which Mongo driver version are you using?

jacob commented 10 years ago

This is an issue with changes to the MongoCollection::insert function in the PHP driver.

See the changelog here: http://www.php.net/manual/en/mongocollection.insert.php

To get the previous behaviour (ie to support legacy code) change the line dizyart mentions as follows

-                                ->insert($data, true);
+                               ->insert($data, array('w' => 1));

This causes the driver to return a true boolean on success instead of an array.