Willi Ballenthin
Willi Ballenthin

Reputation: 6604

How can I execute a JS script file from Pymongo?

I have a MapReduce job for my MongoDB database implemented in a Javascript script file. I've tested it from the commandline and Mongo shell (load("MR_stack.js")). Now I'm using Pymongo within a larger application to access the Mongo database. How can I execute my MR_stack.js script from within Pymongo?

Upvotes: 2

Views: 6982

Answers (2)

Kashyap Rathod
Kashyap Rathod

Reputation: 41

from bson import Binary, Code

You can use this library for running your javascript mapreduce code like this

map = code("""your mapreduce code""")

reducer = code("""your mapreduce code""")

emp = db.orders.map_reduce(mapper, reducer, "moid_details")

Upvotes: 0

Lowgain
Lowgain

Reputation: 81

The database object has an eval method:

http://api.mongodb.org/python/current/api/pymongo/database.html

Upvotes: 7

Related Questions