3

I've been trying to store server side functions in MongoDB (from the client side)

I'm trying this, from the examples:

db.system.js.save({_id: "sum",
              value: function (x, y) { return x + y; }});

But that does not work. I am using Mongoose, so I don't know if it has a wrapper around the plain Mongo DB object.

5
  • What if you encapsulate the value into a string? Commented Mar 27, 2013 at 14:11
  • Problem is that db.system.js does not exist. Commented Mar 27, 2013 at 15:18
  • It should...What is the exact error message you get from trying to run that command above? Commented Mar 27, 2013 at 15:19
  • That db.system is undefined. Mind you: this is on the client side, inside a node.js program. So not in a mongo shell. I can use db.eval. Commented Mar 27, 2013 at 20:04
  • It should allow you connect to the system.js collection through node much the same way, I am no genuis when it comes to node.js Commented Mar 27, 2013 at 20:57

1 Answer 1

5

Use the mongoose-function plugin to add function support to mongoose.

Then create a schema and force its collection name:

new Schema({ value: Function }, { collection: 'system.js' })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.