Jamgreen
Jamgreen

Reputation: 11059

Store a function in MongoDB in Meteor

Is it possible to store a function in a MongoDB collection in Meteor?

I have tried defining my schema with

const SchemaName = new SimpleSchema({
  text: {
    type: String,
  },
  transform: {
    type: Function,
  }
});

CollectionName.attachSchema(SchemaName);

and add a document with

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

but it doesn't seem to work.

What can I do?

Upvotes: 0

Views: 70

Answers (1)

Thai Tran
Thai Tran

Reputation: 9935

I saved function as type "String" and then during loading, I convert it into function by using eval or new Function(). Function is not a type in SimpleScheme

Upvotes: 1

Related Questions