I am using MongoID 6.0.1, and it is easy to request everything you want:
db ||= Mongoid.default_client.database f = """ functionFoo = function (arg){ //----process arg } """ result = db.command({:$eval => f, args: [arg1, arg2, ...arg_n], nolock: true}) @result_data = result.first['retval']
This is not only a function, just every thing you want to do with a team. My example:
db ||= Mongoid.default_client.database f = """ var collectionNames = db.getCollectionNames(), stats = []; collectionNames.forEach(function (n) { stats.push(db[n].stats()); }); stats = stats.sort(function(a, b) { return b['size'] - a['size']; }); return stats; """ result = db.command({:$eval => f, args: [], nolock: true}) @result_data = result.first['retval']
source share