

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
- Related Questions & Answers
- Loop through all MongoDB collections and execute query?
- MongoDB query to implement aggregate function
- MySQL stored procedure to execute SHOW CREATE TABLE?
- How to create MongoDB stored procedure?
- How can we use a MySQL stored function in a database query?
- How to execute SQL update query in a JSP?
- MongoDB aggregate query to sort
- MongoDB query to calculate average
- MongoDB query to sort subdocuments
- MongoDB query to skip documents
- MongoDB query to update tag
- How to work with Stored JavaScript in MongoDB?
- Implement DELETE query in MySQL stored procedure
- MongoDB query to set user defined variable into query?
- MongoDB query to add matched key to list after query?
Advertisements