简体   繁体   English

在mongoDB的system.js中存储库的技术

[英]techniques for storing libraries in mongoDB's system.js

Are there any reliable techniques for storing prototype-based libraries/frameworks in mongoDB's system.js ? 在mongoDB的system.js中是否存在任何可靠的技术来存储基于原型的库/框架? I came across this issue when trying to use dateJS formats within a map-reduce. 尝试在map-reduce中使用dateJS格式时遇到了这个问题。 JIRA #SERVER-770 explains that objects' closures - including their prototypes - are lost when serialized to the system.js collection, and that this is the expected behavior. JIRA #SERVER-770解释了当序列化到system.js集合时,对象的关闭(包括其原型)会丢失,并且这是预期的行为。 Unfortunately, this excludes a lot of great frameworks such as dojo , Google Closure , and jQuery . 不幸的是,这排除了许多很棒的框架,例如dojoGoogle ClosurejQuery

Is there a way to somehow convert or contain libraries such that they don't rely on prototyping? 有没有办法以某种方式转换或包含不依赖原型的库? There's some promise to initializing before the Map-Reduce and passing them in through the scope object, but I haven't had much luck so far. 可以在Map-Reduce之前进行初始化,然后将它们传递给scope对象,但是到目前为止,我还没有碰到很多运气。 If my approach is flawed, what is a better way to enable server-side javascript re-use for mongo? 如果我的方法有缺陷,那么有什么更好的方法可以使mongo使用服务器端JavaScript?

Every query using JS may reuse or get a brand new JS context, on which stored JS objects are loaded. 每个使用JS的查询都可以重用或获得全新的JS上下文,在该上下文中加载存储的JS对象。 In order to do what you want, you need either: 为了做您想要的,您需要:

  1. mongod to run the stored code automatically when installing it mongod在安装时自动运行存储的代码
  2. mapreduce to have an init method mapreduce有一个init方法

The first is definitely the more interesting feature. 首先肯定是更有趣的功能。 Turns out that mongodb v8 build automatically does it (but not officially supported), but not the official spidermonkey build. 事实证明,mongodb v8构建会自动执行此操作(但未得到官方支持),但不是官方的spidermonkey构建。

Say you store code like: 假设您将代码存储为:

db.system.js.save({ _id: "mylib", value: "myprint = function() { print('installed'); return 'installed';" }

Then in v8 you can use myprint() freely in your code, but with SM you would need to call mylib() explicitly. 然后在v8中,您可以在代码中自由使用myprint(),但是对于SM,则需要显式调用mylib()。

As a workaround you can create another method: 解决方法是创建另一个方法:

db.system.js.save({ _id: "installLib", value: "if (!libLoaded) mylib(); libLoaded = true;" }

And call it from your map() function. 并从您的map()函数调用它。

Created ticket in order to standardize engines and allow automatic run: https://jira.mongodb.org/browse/SERVER-4450 创建票证以使引擎标准化并允许自动运行: https : //jira.mongodb.org/browse/SERVER-4450

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM