Closed arthurkushman closed 5 years ago
No, there are no ability to rename collections now
Hi, found the way to do this via executeCommand
, e.g.:
$collection->getDatabase()->executeCommand([
'renameCollection' => NearestCities::DB_CITIES . '.' . NearestCities::NEAREST_CITIES_X,
'to' => NearestCities::DB_CITIES . '.' . NearestCities::NEAREST_CITIES,
'dropTarget' => true]);
thing to note here is that u should run this command in admin
db context, then it will work properly.
I've sincerely wanted to make a PR, but the problem is that I'm getting the same error on different platforms - MacOS/Ubuntu: PHP Fatal error: Class 'MongoException' not found in /var/sites/php-mongo/src/Exception.php on line 17
My settings for mongodb in php is:
/etc/php/7.1/cli/conf.d/20-mongodb.ini,
mongodb
libmongoc bundled version => 1.8.2
libmongoc SSL => enabled
libmongoc SSL library => OpenSSL
libmongoc crypto => enabled
libmongoc crypto library => libcrypto
libmongoc crypto system profile => disabled
libmongoc SASL => enabled
mongodb.debug => no value => no value
PWD => /var/sites/php-mongo/tests
OLDPWD => /var/sites/php-mongo
$_SERVER['PWD'] => /var/sites/php-mongo/tests
$_SERVER['OLDPWD'] => /var/sites/php-mongo
As u can c I'm using php7.1, probably this is the problem (backward compatibility support by your lib).
You need compatibility layer for php > 7.0. See https://github.com/sokil/php-mongo/blob/master/README.md#installation.
https://docs.mongodb.com/manual/reference/method/db.collection.renameCollection/
In high-load systems there can be issues where one need to import data to collection xxx and then rename it to yyy that currently works on production server.