2

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?

seaders
  • 3,878
  • 3
  • 40
  • 64
  • I wonder couldn't the reason be that MongoId is set explicitly in that insert, but its bytes 4-6 (which are, by [doc](http://php.net/manual/en/class.mongoid.php), a hash of the client's machine hostname) are somehow made invalid with Vagrant setup? Does the insert work without '_id' set? – raina77ow Aug 17 '12 at 11:06
  • @raina77ow, just changed it to $collection->insert(array ("asdf" => 1)); and that didn't work either, thanks for the effort / answer though :) – seaders Aug 17 '12 at 11:07
  • Ok, but does querying this empty `newcollection` work? – raina77ow Aug 17 '12 at 11:09
  • Yup, "var_dump($collection->find())" prints "class MongoCursor#5 (0) { }". – seaders Aug 17 '12 at 11:12
  • 2
    Assuming you're referring to Vagrant as in the [tool for managing virtualized hosting environments](http://vagrantup.com/), this detail is far less relevant than the actual version of Linux, MongoDB, and the Mongo PHP driver that you're using. Can you add some information on versions used? – Stennie Aug 17 '12 at 12:15
  • @Stennie, yeah sorry about that, I thought the answer might be down to a simple Mongo misconfiguration, but the versions of all the stuff, as you said, was what was wrong. All working now. – seaders Aug 17 '12 at 15:53

1 Answers1

0

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.

seaders
  • 3,878
  • 3
  • 40
  • 64
  • I still get this error, i upgraded the version to the newest one, and it didn't solve the issue, anyone can advice? – Liad Livnat Aug 06 '13 at 09:13