Alternatively, if it is difficult to join two ad-hoc tables, then run the mongo shell script post-hoc; they are very easy to program (a couple of "lines" of js) and easy to execute. plus you can apply any necessary conversion, for example, to json / bson arrays allowed in mongo, but not mysql.
provided that the user and user set (or table) are in mangoes.
db.user_role.find({}).forEach(function(doc) { var roles = doc.roles; // convert mysql format here if needed. //var roles_array = JSON.parse(roles) // or whatever? //var alias = doc.alias; // if alias is null empty or ?? // dont upsert to avoid orphaned user_role records db.user.update({"_id": doc.user_id}, {"roles": roles, "alias", doc.alias }, {upsert: false, multi: false}); }
Then execute using mongo shell
mongo localhost: 27017 / test myjsfile.js
source share