Search code examples
phpmongodbinsertphp-mongodbdatabase

MongoDb insert error (php) - BSON doc is X bytes, max is 0


I just started using MongoDB. i can insert new records in terminal with mongo command like:

db.test.insert({var: 'data' }) .

And i can get these records with php, like:

Array
(
    [0] => Array
        (
            [_id] => MongoId Object
                (
                    [$id] => 509d0a4ae6c4d3ca0ba30572
                )

            [deneme] => 1
        )

    [1] => Array
        (
            [_id] => MongoId Object
                (
                    [$id] => 509d09e2a3047c588723f9bf
                )

            [deneme] => 
            [name] => aa
        )

)

But i can not insert record with php like:

$m->insert(array(
'url' => 'http://www.query7.com',
'software' => 'wordpress',
'tutorials' => array('php','javascript','web development'),
));

I GET THIS ERROR: Fatal error: Uncaught exception 'MongoException' with message 'size of BSON doc is 145 bytes, max is 0' in

I have tested with different php classes but i always get same error . What is "size of BSON doc" ?

Thanks


Solution

  • Most probably the problem is with an old version of Mongo. Judging by your answer MongoDb insert error (php) - BSON doc is X bytes, max is 0 and the answer of https://stackoverflow.com/a/12009052/1090562

    Please reply here if the problem will not disappear after a new mongo installation