Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to renameCollection? #169

Closed
arthurkushman opened this issue Oct 26, 2018 · 3 comments
Closed

Is it possible to renameCollection? #169

arthurkushman opened this issue Oct 26, 2018 · 3 comments

Comments

@arthurkushman
Copy link
Contributor

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.

@sokil
Copy link
Owner

sokil commented Oct 27, 2018

No, there are no ability to rename collections now

@arthurkushman
Copy link
Contributor Author

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).

@sokil
Copy link
Owner

sokil commented Oct 29, 2018

You need compatibility layer for php > 7.0. See https://github.com/sokil/php-mongo/blob/master/README.md#installation.

arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Oct 29, 2018
arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Oct 30, 2018
arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Oct 30, 2018
arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Nov 1, 2018
…n MongoCollection, add private method replaceRenameCollection
arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Nov 1, 2018
arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Nov 1, 2018
arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Nov 4, 2018
arthurkushman added a commit to arthurkushman/php-mongo that referenced this issue Nov 4, 2018
sokil added a commit that referenced this issue Nov 4, 2018
@sokil sokil closed this as completed Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants