silent_coder
silent_coder

Reputation: 6522

how to implelement custom mongodb driver

I using mongodb in my poject and interesting how to implement simple mongodb driver which will allow to run mongodb command like in a shell form. Just writing command in javascript and pushing it to mongodb, then geting result and deserializing it.

Upvotes: 0

Views: 81

Answers (1)

WiredPrairie
WiredPrairie

Reputation: 59773

Substitute your connection string in the code below.

While it would be extremely dangerous to provide this generally speaking (as it allows any command to execute), just call the eval function on the instance of the database that's returned.

This code is use the JavaScript/NodeJS driver:

var
    mongodb = require('mongodb'),
    MongoClient = mongodb.MongoClient
;

MongoClient.connect("mongodb://localhost:27017/default?w=1",
    function (err, db) {
        db.eval("db.version()", null, {noLock: true}, function(err, results) {
            console.log(results);                       
    });
});

Upvotes: 1

Related Questions