
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to create MongoDB stored procedure?
The following is the syntax to create MongoDB stored procedure −
db.system.js.save ( { _id:"yourStoredProcedueName", value:function(argument1,....N) { statement1, . . N } } );
Now implement the above syntax. The query to create a stored procedure is as follows −
> db.system.js.save ( { _id:"addTwoValue", value:function(a,b) { return a+b } } );
The following is the output −
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : "addTwoValue" })
Now you can call the stored procedure using eval(). The query is as follows −
> db.eval("return addTwoValue(100,25)"); 125
- Related Articles
- MySQL Stored Procedure to create a table?
- What is STORED PROCEDURE in a DB2? How will you create a new stored procedure?
- MySQL stored procedure to execute SHOW CREATE TABLE?
- What is stored procedure and how can we create MySQL stored procedures?
- How can we create MySQL stored procedure to calculate the factorial?
- How can I create MySQL stored procedure with IN parameter?
- How can I create MySQL stored procedure with OUT parameter?
- How can I create MySQL stored procedure with INOUT parameter?
- How to create a Stored procedure in Oracle database using JDBC API?
- How to create a Stored procedure in a database using JDBC API?
- Create a stored procedure with delimiter in MySQL
- How to suppress MySQL stored procedure output?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- Create variables in MySQL stored procedure with DECLARE keyword
- How can I create a stored procedure to insert values in a MySQL table?

Advertisements