Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
/*
This file contains proprietary software owned by Motorola Mobility, Inc.<br>
No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br>
(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
*/
var Db = require('mongodb').Db;
var BSON = require('mongodb').BSONPure
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
module.exports = MongoDbProvider;
function MongoDbProvider(host, port) {
this._db = new Db("screening", new Server(host, port, {auto_reconnect: true}, {}));
this._db.open(function(err, dbConn) {
if (err) {
console.error("Couldn't connect to MongoDB, plese check /docs/MongoDb.md for info on how to setup the MongoDB server", err.message);
process.exit(1);
} else {
console.log("Connected to MongoDB server on " + dbConn.serverConfig.host + ":" + dbConn.serverConfig.port + ", database: " + dbConn.databaseName);
}
});
return this;
var Storage = function(options) {
// set options and load defaults if needed
this.options = options || {};
this.options.host = this.options.host || 'localhost';
this.options.port = this.options.port || mongo.Connection.DEFAULT_PORT;
this.collectionName = 'events';
this.store = new mongo.Db('eventstore'
, new mongo.Server(this.options.host, this.options.port, {}), {});
this.store.addListener("error", function(error) {
console.log("Error connecting to mongo -- perhaps it isn't running?");
});
this.client = undefined;
this.store.open(function(err, client) {
this.client = client;
}.bind(this));
};
function onOpened(err, db) {
// TODO: report errors somewhere?
if (err) { return ; }
_db = db;
arbiter.emit("db_open", db);
}
if (db_url) {
var options = {
uri_decode_auth: true,
server: server_options,
db: db_options
};
mongo.connect(db_url, options, onOpened);
} else {
var port = mongo.Connection.DEFAULT_PORT;
var mongoserver = new mongo.Server(host, port, server_options);
var db_connector = new mongo.Db(db_name, mongoserver, db_options);
_db = db_connector;
}
return {
/**
* This function returns a collection from the mongo DB, making sure that
* the DB is created before using it.
*
* @method get
* @param {String} db_name* A namespaced name for the DB
* @param {Function} cb Function to run when the DB is returned.
*/
get: function() {
var cb;
var app = express(),
http = require('http'),
server = http.createServer(app);
var WebSocketServer = require('websocket').server;
// io = require('socket.io').listen(server);
//var WebSocketServer = require('ws').Server;
var csv = require('csv');
var sys = require('sys');
var fs = require('fs');
var path = require('path');
var config = require('./config.json');
var mongo = require('mongodb');
var BSON = mongo.BSONPure;
var Db = mongo.Db,
Connection = require('mongodb').Connection,
Server = require('mongodb').Server;
var passport = require('passport'),
TwitterStrategy = require('passport-twitter').Strategy;
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var multer = require('multer');
var upload = multer({
dest: config.uploadDirectory
});
var host = process.env['MONGO_NODE_DRIVER_HOST'] != null ? process.env['MONGO_NODE_DRIVER_HOST'] : 'localhost';
var port = process.env['MONGO_NODE_DRIVER_PORT'] != null ? process.env['MONGO_NODE_DRIVER_PORT'] : Connection.DEFAULT_PORT;
var rservs = []
for( var i = 0; i < conf.replicaset.servers.length; i++ ) {
var servconf = conf.replicaset.servers[i]
rservs.push(new mongo.Server(servconf.host,servconf.port,{native_parser:false,auto_reconnect:true}))
}
var rset = new mongo.ReplSetServers(rservs)
dbinst = new mongo.Db(
conf.name, rset
)
}
else {
dbinst = new mongo.Db(
conf.name,
new mongo.Server(
conf.host || conf.server,
conf.port || mongo.Connection.DEFAULT_PORT,
{}
),
{native_parser:false,auto_reconnect:true}
)
}
// FIX: error reporting sucks on login fail
dbinst.open(function(err){
if( !error({actid$:'init'},err,cb) ) {
minwait = MIN_WAIT
if( conf.username ) {
dbinst.authenticate(conf.username,conf.password,function(err){
// do not attempt reconnect on auth error
if( err) {
var Db = require('mongodb').Db;
var Connection = require('mongodb').Connection;
var Server = require('mongodb').Server;
var connectionInstance;
var conf = require('../config/conf.js');
module.exports = function(callback) {
//if already we have a connection, don't connect to database again
if (connectionInstance) {
callback(null,connectionInstance);
return;
}
//db name //db ip db port
var db = new Db(conf.DatabaseName, new Server(conf.mongoIp,conf.mongoPort,{ auto_reconnect: true }));
db.open(function(error, databaseConnection) {
//if (error) throw new Error(error);
if (error){callback(error,null)}
else{
console.log("database connection successfully in connection class")
var fixtures = require('../mongodb-fixtures.js');
var Db = require('mongodb').Db,
Connection = require('mongodb').Connection,
Server = require('mongodb').Server;
var db = new Db('wines', new Server("localhost", Connection.DEFAULT_PORT, {}));
var data = fixtures.load();
fixtures.save(data, db, function() {
db.close();
console.dir(data);
});
var express = require('express'),
Db = require('mongodb').Db,
Server = require('mongodb').Server,
Connection = require('mongodb').Connection,
http = require('http'),
debug = require('util').debug,
inspect = require('util').inspect;
var host = 'localhost';
var port = Connection.DEFAULT_PORT;
var db = new Db('node-mongo-examples', new Server(host, port, {}), {native_parser:false});
var ObjectID = db.bson_serializer.ObjectID;
var app = express.createServer(
express.cookieParser(),
express.bodyParser(),
express.session({ secret: 'keyboard cat' })
);
var settings = require('../settings'),
Db = require('mongodb').Db,
Connection = require('mongodb').Connection,
Server = require('mongodb').Server;
module.exports = new Db(settings.db, new Server(settings.host, settings.port), {safe: true});
var MongoDB = exports.MongoDB = function (options) {
options = options || {}
if (!options.db) {
throw new Error("Cannot log to MongoDB without database name.");
}
this.name = 'mongodb';
this.db = options.db;
this.host = options.host || 'localhost';
this.port = options.port || mongodb.Connection.DEFAULT_PORT;
this.collection = options.collection || "log";
this.safe = options.safe || true;
this.level = options.level || 'info';
this.silent = options.silent || false;
};