PHP & Mongo in Vagrant, “ Uncaught exception '

2019-07-13 21:26发布

问题:

I've a Vagrant setup with Mongo and PHP within, but any time I try to run a simple insert into a Mongo collection, I get the above error,

Uncaught exception 'MongoException' with message 'size of BSON doc is 210 bytes, max is 0'

The actual code is

$mongo = new Mongo();
$mongo->newdb->drop();
$db = $mongo->newdb;
$collection = $db->newcollection;
$collection->insert(array ( "_id" => new MongoId("4ec1019f87484465ae4d777e"), "id" => 1));

There's nearly no info about this error online, and near all my Vagrant setup is what's stated online to work. Anybody with an idea why it fails?

回答1:

Sorry about that, this was down to a very old version of Mongo I had installed, something like 1.4, because of a Vagrant misconfiguration. Once I sorted that out and installed the most recent one (MongoDB shell version: 2.0.7), everything worked like a charm. Thanks for the help though.