java 调用Mongodb存储过程

Mongodb3.0以后 db.eval() Deprecated since version 3.0.若是mongodb要写存储过程(js脚本),是不是有什么替代的执行方法。同时mongodb -java-driver3.0中DB类也已经置为Deprecated,其方法eval(),doEval()也一样,而MongoDataBase类中我没有找到执行脚本的方法,请问各位大神是不是有什么替代的方法,还是Mongodb不再建议执行js脚本,但我项目有执行类似存储过程的需求,可有解决方案?

1个回答

You can create stored procedures on MongoDB in form of Javascript functions which are stored in the special collection db.system.js, but that's usually not advisable. Most of the reasons why stored procedures are useful for relational databases do not apply to MongoDB. Instead of calling a server-sided function from Java you should just implement said function directly in Java.

But when you still want to use them, creating such functions is documented as "storing functions server-sided". To execute them, you can use DB.command() or DB.doEval().

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐