Green Elephant
Green Elephant

Reputation: 3

Call MongoDB stored function from pymongo

I have the following function stored in mongodb:

db.system.js.save({
    _id: "testFunc",
    value: function() {
        return db.clients.find_one({}, {"_id" : False});
    }
});

How do I call the function above from python using pymongo? I have already tried db.eval('testFunc') and it doesn't work. The method is deprecated.

Upvotes: 0

Views: 658

Answers (1)

Belly Buster
Belly Buster

Reputation: 8814

eval, system_js etc. are all deprecated.

While you can still create javascript functions on the server, it comes with a clear warning:

Do not store application logic in the database. There are performance limitations to running JavaScript inside of MongoDB. Application code also is typically most effective when it shares version control with the application itself.

Upvotes: 2

Related Questions