I have a mongo db script in a js file:
query.js
//conn = new Mongo();
//db = conn.getDB("dbName");
functionFoo = function (arg){
//----process arg
}
also I have an array of args known as args_array, (that I fetch from database using mongoid) for which I want to do something like this:
args_array.each do |arg|
//some how call functionFoo(arg) from the query.js file
end
is this possible in rails?
I am able to execute the file from terminal but I want to wrap it in my application so that I can use it from rails console.
mongoshell) in order for these to make sense. What's your actual requirement -- do you just need to evaluate a list of saved queries in a file, or do they have to be JavaScript functions?execmay be, but the function takes an argument from a ruby array, this is my exact problemexecand define these for yourmongoshell script with--eval .... However, rather than using a mix of JavaScript + Ruby, I think it would be much more sensible to write all the functions in one language. You could either get the query arguments you need via JavaScript, or port your existing JavaScript functions to Ruby.mongoshell, those are still executed on the client side similar to queries in Ruby. Spawningmongoshells to run functions & queries from the Rails console adds complexity & overhead if you could run those queries directly via the Ruby driver. The Ruby driver will also have richer I/O methods compared to themongoshell. It would help if you can post an actual example of a function & query you are running and describe the intended goal. There is likely a more direct approach.