How can I ask MongoDB to evaluate some JavaScript in order to obtain value for a field?

*爱你&永不变心* 提交于 2019-11-28 13:02:30

See the following URL on the MongoDB documentation:

http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Storingfunctionsserverside

There is a special system collection called system.js that can store JavaScript functions to be reused.

Note though, that the support and performance of server-sided code (equivalent to stored procedures) is still a little poor (details in link).

Edit:

To call a stored procedure from Go using the mgo driver use the mgo.Database type's Run() method (direct link) and issue an eval command with the Javascript code to be executed server-side as argument. Something like:

db.Run(bson.M{"eval": "myStoredFunction();"})

code untested

It is not possible to have code evaluated in a MongoDB insert statement.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!