mongodb-expressions
Version:
MongoDB expressions for fire.js
58 lines (52 loc) • 1.42 kB
JavaScript
var mongodb = require('mongodb');
var path = require('path')
var fireMongo = require('../index.js')
function createTestDbConfig() {
return {
host: '127.0.0.1',
port: 27017,
db: 'mongodb-expressions-tests',
options: {
}
}
}
function configRuntime(runtime, finished, skipTestConfig) {
if(!runtime.applicationName) {
runtime.applicationName = "mongodb-expressions"
}
runtime.setBaseDir(path.dirname(module.filename))
runtime.loadModuleInstance(fireMongo, "mongodb-expressions")
runtime.events.on('load', function() {
if(!skipTestConfig) {
runtime.getModuleConfiguration('mongodb-expressions')['generic'] = createTestDbConfig()
}
})
runtime.load(function(initError){
finished(initError)
})
}
module.exports.configRuntime = configRuntime
function dropCollection(callback,obj, collname) {
if(collname === undefined) {
throw "dropCollection requires a collection name"
}
var config = createTestDbConfig()
var server = new mongodb.Server(config.host, config.port, config.options);
new mongodb.Db(config.db, server, {}).open(function (error, client) {
if(error) {
throw error
} else {
var collection = new mongodb.Collection(client, collname);
collection.remove({}, function(err, done) {
if(err) {
client.close()
throw err
} else {
client.close()
callback.apply(obj)
}
})
}
});
}
module.exports.dropCollection = dropCollection