Permalink
Browse files

added db.eval, renamed db.drop to db.dropDatabase, tweaked server-sid…

…e error message
  • Loading branch information...
1 parent 9dd3166 commit b0d6b9d820a23759dae7dcc9d9f20779ed42ab45 @marcello3d committed Apr 29, 2011
Showing with 21 additions and 5 deletions.
  1. +1 −1 examples/mongolian_trainer.js
  2. +19 −3 lib/db.js
  3. +1 −1 test/simple-test.js
@@ -11,7 +11,7 @@ var db = server.db("mongolian_trainer"),
medium = db.collection("medium"),
large = db.collection("large")
-//db.drop(asyncLog("dropped database"))
+//db.dropDatabase(asyncLog("dropped database"))
small.ensureIndex({foo:1},asyncLog("ensuredIndex!"))
medium.ensureIndex({foo:1})
View
@@ -1,5 +1,6 @@
/* Mongolian DeadBeef by Marcello Bastea-Forte - zlib license */
-var crypto = require('crypto')
+var crypto = require('crypto'),
+ util = require('util')
var safetyNet = require('./util').safetyNet,
MongolianCollection = require('./collection'),
@@ -56,7 +57,7 @@ MongolianDB.prototype.collectionNames = function(callback) {
MongolianDB.prototype.queryCommand = function(query, callback) {
this.collection('$cmd').findOne(query, safetyNet(callback, function(result) {
if (!result.ok) {
- var error = new Error("Server Error: " + result.errmsg)
+ var error = new Error("Server Error: " + util.inspect(result))
error.result = result
callback(error)
} else {
@@ -150,10 +151,25 @@ MongolianDB.prototype.auth = function(username, password, callback) {
/**
* !!! Removes the entire database !!!
*/
-MongolianDB.prototype.drop = function(callback) {
+MongolianDB.prototype.dropDatabase = function(callback) {
this.queryCommand({ dropDatabase:1 }, callback)
}
+MongolianDB.prototype.eval = function(execFunction, args, callback) {
+ var command = { $eval:new bson.Code(execFunction) }
+
+ if (arguments.length > 1) {
+ callback = arguments[arguments.length-1]
+ if (callback instanceof Function) {
+ command.args = Array.prototype.slice.call(arguments,1,arguments.length-1)
+ } else {
+ command.args = Array.prototype.slice.call(arguments,1)
+ callback = undefined
+ }
+ }
+ this.db.queryCommand(command, callback)
+}
+
/**
* Gets the last error message from the server on this connection
*
View
@@ -8,7 +8,7 @@ vows.describe('Mongolian DeadBeef, I choose you!').addBatch({
topic: function () {
var db = new Mongolian({ keepAlive: 1 }).db('mongolian_test')
var callback = this.callback
- db.drop(function(err) { callback(err, !err && db) })
+ db.dropDatabase(function(err) { callback(err, !err && db) })
},
"is not null": function (db) {
assert.isObject(db)

0 comments on commit b0d6b9d

Please sign in to comment.