MongoDB 存储过程等价物

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3876049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:48:57  来源:igfitidea点击:

MongoDB Stored Procedure Equivalent

stored-proceduresmongodbgeolocationmapreduce

提问by Abe

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.

我有一个包含商店列表的大型 CSV 文件,其中一个字段是 ZipCode。我有一个名为 ZipCodes 的单独 MongoDB 数据库,它存储任何给定邮政编码的纬度和经度。

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.

在 SQL Server 中,我将执行一个名为 InsertStore 的存储过程,它会在 ZipCodes 表上进行查找以获取相应的纬度和经度并将数据插入到 Stores 表中。

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.

有没有类似于 MongoDB 中存储过程的概念?基本上,对于每个插入,我需要查找该商店​​的纬度和经度并将其保存。

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

我对 Map/Reduce 的概念不太熟悉,但这在这里是否相关?谢谢!

回答by Justin Dearing

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 articleon Mike Dirolf's blog.

最接近 mongodb 中存储过程的东西是存储的 javascript。Mike Dirolf 的博客上的这篇文章对存储的 javascript 做了很好的介绍。

回答by Guido Mocha

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.

不要将应用程序逻辑存储在数据库中。在 MongoDB 中运行 JavaScript 存在性能限制。当应用程序代码与应用程序本身共享版本控制时,它通常也是最有效的。

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

所以在 mongodb 中没有任何等效的存储过程。

回答by Victor

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

您可以通过 MongoDB Stitch 在云上使用触发器和函数。