【问题标题】:Store a function in MongoDB in Meteor在 Meteor 中存储 MongoDB 中的函数
【发布时间】:2016-01-19 03:03:21
【问题描述】:

是否可以在 Meteor 的 MongoDB 集合中存储函数?

我尝试使用

定义我的架构
const SchemaName = new SimpleSchema({
  text: {
    type: String,
  },
  transform: {
    type: Function,
  }
});

CollectionName.attachSchema(SchemaName);

并添加一个文档

CollectionName.insert({ text: "Some text", transform: function (value) { return value * 2; } });

但它似乎不起作用。

我能做什么?

【问题讨论】:

    标签: node.js mongodb meteor meteor-collection2 simple-schema


    【解决方案1】:

    我将函数保存为“字符串”类型,然后在加载过程中,我使用evalnew Function() 将其转换为函数。 Function 不是 SimpleScheme 中的类型

    【讨论】:

    • 现在您必须非常小心该函数的来源,否则这将成为理想的攻击媒介。
    • 是的,保存的功能是供我们内部使用的表单构建器使用的,因此它在控制之下
    • 所以根本不可能将函数保存到集合中?那我怎样才能得到我想要的呢?我是否应该在我的代码中只包含一些预定义的函数,然后将函数名保存在集合中而不是保存整个函数?
    猜你喜欢
    • 2013-08-13
    • 1970-01-01
    • 2015-06-19
    • 2013-06-24
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多