php mongodb : Call to undefined method MongoDB::insert() in db.php php mongodb : Call to undefined method MongoDB::insert() in db.php php php

php mongodb : Call to undefined method MongoDB::insert() in db.php


Each DB contains one or many collections. You are trying to insert into the DB, instead of the collection.

I've not used that extension, but that method doesn't exist in the MongoDB class according to the documentation. Instead, it is MongoCollection::insert. You get at a collection by:

// $collection = $mongo->selectDB("foo")->selectCollection("bar");$collection = $mongo->foo->bar; $collection->insert(array('x' => 1));

(The commented line is equivalent to the line below it.)

I'm guessing that you are doing something like:

$collection = $mongo->foo;$collection->insert(array('x' => 1));

(Edit: I didn't see your code snippet the first time. That is precisely what you are doing.)

I suggest that you read the tutorial for more information.