Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fredrikpaulin opened this issue Feb 6, 2013 · 3 comments
Open

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

fredrikpaulin opened this issue Feb 6, 2013 · 3 comments

Comments

@fredrikpaulin
Copy link

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
Copy link

dizyart commented Feb 11, 2013

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
Copy link

dizyart commented Feb 11, 2013

Btw, which Mongo driver version are you using?

@jacob
Copy link

jacob commented Feb 19, 2014

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants