doctrine / mongodb

PHP MongoDB Abstraction Layer

Home Page:https://www.doctrine-project.org/projects/mongodb.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot create collection using Database::createCollection() with MongoDB >=4.1.10

xodmqjw opened this issue · comments

Cannot create a collection via Doctrine\MongoDB\Database::createCollection() because in this method 'max' and 'size' fields are explicitly set to 0.

$options = is_array($cappedOrOptions)
            ? array_merge(['capped' => false, 'size' => 0, 'max' => 0], $cappedOrOptions)
            : ['capped' => $cappedOrOptions, 'size' => $size, 'max' => $max];

$options['capped'] = (boolean) $options['capped'];
$options['size'] = (integer) $options['size'];
$options['max'] = (integer) $options['max'];

Starting with 4.1.10 MongoDB does not allow to use createCollection() with set fields for 'max', 'size' and false value for the field 'capped':

MongoDB v.4.1.9:

> db.createCollection("test", {capped: false, max: 0, size: 0})
{ "ok" : 1 }

MongoDB v.4.1.10

> db.createCollection("test", {capped: false, max: 0, size: 0})
{
	"ok" : 0,
	"errmsg" : "the 'capped' field needs to be true when either the 'size' or 'max' fields are present",
	"code" : 72,
	"codeName" : "InvalidOptions"
}

This library is no longer maintained and will not receive bug fixes except for critical security issues. The library is built on the legacy driver, which does not support newer MongoDB releases.

If you are using this library standalone, please switch to the mongodb/mongodb package, which is part of the supported MongoDB driver for PHP, along with the ext-mongodb extension.
If you are using this library as part of MongoDB ODM, please upgrade to ODM 2.0, which is no longer built on this library. If you cannot upgrade to 2.0 yet, I would suggest running it with MongoDB 4.0 or lower until you can upgrade.