Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB Stored Procedure Equivalent

I have a large CSV file containing a list of stores, in which one of the field is ZipCode. I have a separate MongoDB database called ZipCodes, which stores the latitude and longitude for any given zip code.

In SQL Server, I would execute a stored procedure called InsertStore which would do a look up on the ZipCodes table to get corresponding latitude and longitude and insert the data into the Stores table.

Is there something similar to the concept of stored procedures in MongoDB for this? Basically, for each insert I need to look up the latitude and longitude for that store and save that as well.

I am not too familiar with the concept of Map/Reduce, but would that be relevant here? Thank you!

like image 352
Abe Avatar asked Oct 06 '10 19:10

Abe


People also ask

What is the equivalent of stored procedure in MongoDB?

While MongoDB does not offer stored procedures as traditional relational databases do, it provides multiple tools that you can use to achieve the same result. By using aggregation pipelines with the proper indexes, you can perform resource-intensive queries from the database server.

Does MongoDB use stored procedures?

First and foremost, MongoDB does not support Stored Procedures, but it does provide a stored javascript feature. This feature offers similar functions and allows writing code in Javascript. It might seem strange but in a real language, it is better to program.

Which command in MongoDB is equivalent to SQL?

The concat function is a MongoDB string aggregation operators. Through mapping SQL functions to MongoDB operators, NoSQLBooster for MongoDB allows you to use all MongoDB aggregation operators as SQL functions in you SQL statement. No $ prefix with MongoDB operator and collection field name.


2 Answers

The closest thing to an equivalent of a stored procedure in mongodb is stored javascript. A good introduction to stored javascript is available in this article on Mike Dirolf's blog.

like image 104
Justin Dearing Avatar answered Sep 19 '22 10:09

Justin Dearing


NOTE that according to the reference:

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.

So there is not any equivalent for stored procedure in mongodb.

like image 29
Guido Mocha Avatar answered Sep 18 '22 10:09

Guido Mocha