0

I use node-mongodb-native in my project and I need to load some JavaScript file with my custom functions like in the following tutorial

My code for connecting to database looks like the following:

var mongoClient = new MongoClient(new Server('localhost', 27017, {
        socketOptions: {keepAlive: 1}
        , auto_reconnect: true
        , poolSize: 10
    }),
{
    native_parser: true
    , w:1
});

mongoClient.open(function (err, mongoClient) {
    if (err) return callback(err);

    var db = mongoClient.db('test');

    console.log('Database connect success!');

    // ... application code
});

I need to load underscore.js file into mongodb to be possible use it functions inside server-side functions saved by using db.system.js.save

I can't find a way of doing that. Please help me.

Erik
  • 14,060
  • 49
  • 132
  • 218
  • The node.js equivalent would be to use `require`. – JohnnyHK Oct 08 '14 at 18:28
  • @xShirase I've added code example but I don't understand how could I load `myscript.js` into the mongodb? – Erik Oct 08 '14 at 18:30
  • @JohnnyHK I need to load `myscript.js` into mongodb – Erik Oct 08 '14 at 18:31
  • 1
    What do you mean by "load `myscript.js` into mongodb"? What are you trying to do? – JohnnyHK Oct 08 '14 at 18:36
  • I'm trying execute server-side functions via `db.eval( "echoFunction( 'test' )" )` and need access to `myscript.js` functions – Erik Oct 08 '14 at 18:38
  • When I say "load `myscript.js` into mongodb" I mean to load and run a JavaScript file into the current shell environment. Like as the following http://docs.mongodb.org/manual/reference/method/load/ – Erik Oct 08 '14 at 18:40
  • Do you understand what I mean? – Erik Oct 08 '14 at 18:52
  • I think so, but I don't know a way to do what you're looking for. – JohnnyHK Oct 08 '14 at 18:57
  • I it possible to provide js file into connection config? – Erik Oct 08 '14 at 18:59
  • I'm looking for something like the following http://docs.mongodb.org/manual/tutorial/write-scripts-for-the-mongo-shell/#execute-a-javascript-file – Erik Oct 08 '14 at 19:12

0 Answers0