Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to rename a MongoDB collection

Hello everybody,
I am trying to do something very simple; using Talend Open Studio for Big Data to rename a MongoDB collection. But I have some issues and I can not execute it successfully.
First, I use a tMongoDBRow component where I have configured everything about the connection. Then in Function field I wrote this:
"db.dim_division.renameCollection('dim_division_old',true);"
And when I execute it, this is the error:
connecting to socket on port 3695
connected
{ "serverUsed" : "xxxx:27017" , "ok" : 0.0 , "errmsg" : "not authorized on DATABASE to execute command { $eval: \"db.dim_division.renameCollection('dim_division_old',true);\", args: [] }" , "code" : 13}
disconnected

My server is a remote server. I read Mongodb docs and it says that user needs to have all privileges due to the fact Talend is using $eval behind the scenes.
Some questions:
1) $eval is deprecated  in MongoDB 3.0. Is Talend going to change the way it executes theses functions?
2) Should I now give all privileges to the user in order to be able to execute $eval?
3) There is another way to do such simple action as renaming a collection?
4) Where can I found further documentation about executing commands (execute command option) and functions with tMongoDBRow?
Thank you in advanced
Regards
Labels (2)
6 Replies
Anonymous
Not applicable
Author

Hi
I made a testing on version 5.6.2 and it works,  tMongoDBRow  uses  mongo-2.8.0.jar in this version. Uncheck the 'Execute command' box and type in the command as below:
"db.oldname.renameCollection('newName')"

Best regards
Shong
amarouni
Contributor

Hello jmartinez,
1- The $eval and $doEval functions are not deprecated as of Mongo 3.0 Java API () which we use behind the scenes. They are deprecated on the mongoshell and will be deprecated soon in the Java API.
2- If you're planning to execute arbitrary code on your mongodb instance (using eval) you should, from a security perspective, have the full privileges on the database.
3- 4- In the next version of the tMongoDBRow we're moving from eval to command (runCommand) (-). Note that renaming a collection using the command (runCommand) requires access to the admin database.
By the way, the call should succeed on non-secure MongoDB instance. What type of authentication you're using ?  
Thanks,
Anonymous
Not applicable
Author

 Regards  shongHi
I made a testing on version 5.6.2 and it works,  tMongoDBRow  uses  mongo-2.8.0.jar in this version. Uncheck the 'Execute command' box and type in the command as below:
"db.oldname.renameCollection('newName')"

Best regards
Shong
Hello shong:

Thank you for your answer. Yes, it works properly this way when I configure the security for using $eval. 

Regards
Anonymous
Not applicable
Author

Hello jmartinez,
1- The $eval and $doEval functions are not deprecated as of Mongo 3.0 Java API () which we use behind the scenes. They are deprecated on the mongoshell and will be deprecated soon in the Java API.
2- If you're planning to execute arbitrary code on your mongodb instance (using eval) you should, from a security perspective, have the full privileges on the database.
3- 4- In the next version of the tMongoDBRow we're moving from eval to command (runCommand) (-). Note that renaming a collection using the command (runCommand) requires access to the admin database.
By the way, the call should succeed on non-secure MongoDB instance. What type of authentication you're using ?  
Thanks,

Hello amarouni:
Thank you for your answer too.
1- Thank you for the info. Certainly I checked mongoshell not Java API.
2- I don't want to execute arbitrary code, just collection rename. But as far as I know, this is the only way, right?.
3 & 4- Good news Smiley Happy. Do you know the roadmap for this change?. I know that I need to have more privileges than usual but far from all privileges for all actions as now.
I am using MongoDB authentication and it works properly now after giving to the user a special role like all privileges for all actions.
Regards
amarouni
Contributor

The new changes should be available in Talend 6.1.1. I'll be working on this feature so I'll keep you update on the progress.
Best Regrads,
Anonymous
Not applicable
Author

The new changes should be available in Talend 6.1.1. I'll be working on this feature so I'll keep you update on the progress.
Best Regrads,

Hello amarouni:
Thank you for your efforts.
Regards