Pymongo get eval results

44 views
Skip to first unread message

Joel

unread,
Jun 30, 2015, 2:49:38 PM6/30/15
to mongod...@googlegroups.com
I'm using pymongo to write a program that takes a script file and sends it to my MongoDb server. My question is, does the eval method return anything containing the results from running the script code? Is there something else I can do to get all the past query results? Here is the code running the script.

def processScript(self, filename):
self.client = pymongo.MongoClient('localhost')
db = self.client.test
data = ""
# read the .js file into a string
with open(filename) as f:
data = data + f.read()
try:
# Pass the string to mongodb be evaluated
db.eval(data)
except Exception as e:
# TODO: Find out the actual exception that would be thrown.
print "Error running script \'%s\': %s" % (filename, e)
sys.exit()

Bernie Hackett

unread,
Jul 1, 2015, 5:06:06 PM7/1/15
to mongod...@googlegroups.com, joel_...@gap.com
I highly recommend that you do not use eval. First of all, the performance of eval is poor. A global lock is taken while the javascript is being evaluated, blocking other operations. Secondly, when using authentication you must have essentially 'root' roles and be authenticated to the admin database to use eval at all.

Why are you reading operations out of a JSON file? Could they be translated to Python?
Reply all
Reply to author
Forward
0 new messages