0

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.

5
  • If I read the doc correctly, it should be db.system_js.testFunc(). stackoverflow.com/questions/16774889/… Commented Jan 22, 2022 at 19:34
  • Unfortunately, I have tested that method too and it does not work. Commented Jan 22, 2022 at 19:39
  • 1
    HOW does it "not work"? Commented Jan 22, 2022 at 19:39
  • Is this a real function? It's a simple findOne - there is no need for a stored function. Commented Jan 22, 2022 at 23:10
  • The purpose was to understand how to call a stored function in mongodb from python. The above function is just for testing. Commented Jan 23, 2022 at 11:46

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.