Quantcast
Channel: Techathon »» Mongodb | Techathon
Viewing all articles
Browse latest Browse all 3

How to rename collection in mongodb using php ?

$
0
0

Mongodb through error “access denied; use admin db”, “ok” : 0 if you try to rename mongo collection with out admin user.

Use below code to rename collection mongodb using php (mongo client)

 $queryRenameAndDrop = array("renameCollection" => "Database.OldName", "to" => "Database.NewName", "dropTarget" => "true");

 $mongo->admin->command($queryRenameAndDrop);

Mongo Query for same:

use database
db.auth(user, pass)

use admin
db.runCommand( { renameCollection: "database.oldcollection", to: "database.newcollection" });

The post How to rename collection in mongodb using php ? appeared first on Techathon.


Viewing all articles
Browse latest Browse all 3

Trending Articles