MongoDB Stored Procedure Equivalent

Stored ProceduresMongodbGeolocationMapreduce

Stored Procedures Problem Overview


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!

Stored Procedures Solutions


Solution 1 - Stored Procedures

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.

Solution 2 - Stored Procedures

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.

Solution 3 - Stored Procedures

You could use Triggers and Functions on the cloud with MongoDB Stitch.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAbeView Question on Stackoverflow
Solution 1 - Stored ProceduresJustin DearingView Answer on Stackoverflow
Solution 2 - Stored ProceduresGuido MochaView Answer on Stackoverflow
Solution 3 - Stored ProceduresHugo LafView Answer on Stackoverflow