
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MongoDB Query to Execute Stored Function
JavaScript function can be saved for reuse using a system collection called system.js. To store a function, use the db.collection.save(),
Let us first create a function. Following is the query −
> db.system.js.save({ ... _id: "displayMessage", ... value: function (data) { ... return 'The Name is: ' + data; ... } ... })
This will produce the following output −
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : "displayMessage" })
Following is the query to execute stored function −
> db.eval("displayMessage('John')") WARNING: db.eval is deprecated
This will produce the following output −
The Name is: John
Advertisements