How to use the mongodb.Server function in mongodb

To help you get started, we’ve selected a few mongodb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rmeschian / javascript-ecosystem-tutorials / mongodbMapReduceWithNodeJSExample.js View on Github external
// node mongodbMapReduceWithNodeJSExample.js

var mongodb_db = require('mongodb').Db;
var mongodb_connection = require('mongodb').Connection;
var mongodb_server = require('mongodb').Server;

var host = 'localhost';
var port = mongodb_connection.DEFAULT_PORT;
var db = new mongodb_db('sampleDB', new mongodb_server(host, port, {}), {
    native_parser : false
});


// --------------


function init(callback) {
    db.open(function() {
        db.dropCollection('sample', function(err, result) {
            seedData(callback);
        });
    });
}

function seedData(callback) {
github cn007b / my / ed / nodeJs / _ruBookPauersS / mongo4.node.js View on Github external
/*
$inc       Приращение значения поля на конкретную величину.
$set       Устанавливает поле, как было показано в предыдущем примере.
$unset     Удаление поля
$push      Добавление значения к массиву, если поле является массивом (с преобразованием поля в массив, если поле им не является).
$pushAll   Добавление нескольких значений к массиву.
$addToSet  Добавление к массиву, только если поле является массивом.
$pull      Удаление значения из массива.
$pullAll   Удаление из массива нескольких значений.
$rename    Переименование поля.
$bit       Выполнение поразрядной операции.
*/
var mongodb = require('mongodb');
var server = new mongodb.Server('localhost', 27017, {auto_reconnect: true});
var db = new mongodb.Db('exampleDb', server);
// открытие соединения с базой данных
db.open(function(err, db) {
    if(!err) {
        // доступ к коллекции виджетов или создание этой коллекции
        db.collection('widgets',function(err, collection) {
            // обновление
            collection.update(
                {id:4},
                {$set : {title: 'Super Bad Widget'}},
                {safe: true},
                function(err, result) {
                    if (err) {
                        console.log(err);
                    } else {
                        console.log(result);
github hapijs / hapi / lib / cache / mongo.js View on Github external
this.startPending = [callback];

    var connected = function (err) {

        self.isConnected = !err;

        for (var i = 0, il = self.startPending.length; i < il; ++i) {
            self.startPending[i](err);
        }

        self.startPending = null;
    };

    // Create client

    var server = new MongoDB.Server(this.settings.host, this.settings.port, { auto_reconnect: true, poolSize: this.settings.poolSize });
    this.client = new MongoDB.Db(this.settings.partition, server, { safe: true });

    // Open connection

    this.client.open(function (err, client) {

        if (err) {
            return connected(new Error('Failed opening connection'));
        }

        // Authenticate

        if (self.settings.username) {
            self.client.authenticate(self.settings.username, self.settings.password, function (err, result) {

                if (err ||
github johnpapa / ng-demos / cc-bmean / src / server / data / dataconfig.js View on Github external
function openMongoDb() {
        /* jshint camelcase:false */
        var dbServer = new mongodb.Server(
            mongoDbConfig.host,
            mongoDbConfig.port,
            {auto_reconnect: true}
        );

        db = new mongodb.Db(mongoDbConfig.dbName, dbServer, {
            strict: true,
            w: 1,
            safe: true
        });

        // Open the DB then get the collections
        db.open(getAllCollections);

        function getAllCollections() {
            // Gets a handle for all of the collections.
github remyla / damas-core / server-nodejs / lib / db / mongodb.js View on Github external
self.connect = function (conf, callback) {
        if (self.conn) {
            return callback(false, self.conn);
        }
        var server = new mongo.Server(conf.host, conf.port, conf.options);
        var db     = new mongo.Db(conf.collection, server);
        db.open(function (err, connection) {
            if (err) {
                self.debug('Unable to connect to the MongoDB database');
                return callback(true);
            }
            self.debug('Connected to the database');
            self.conn = connection;
            self.collection = conf.collection;
            callback(false, self.conn);
        });
    }; // connect()
github lsm / nodepress / core / db.js View on Github external
function connect(server, callback) {
    var type = typeof server;
    if (type  == 'string') {
        mongo.connect(server, callback);
        return;
    } else if (type == 'object' && !Array.isArray(server)) {
        var db = new mongo.Db(server.dbname, new mongo.Server(server.host, server.port, server.serverOptions), server.dbOptions);
        db.open(callback);
        return;
    }
    throw new Error('Server configuration not correct.');
}
github hyperstudio / MIT-Annotation-Data-Store / node_modules / mongoose / lib / drivers / node-mongodb-native / connection.js View on Github external
this.host.forEach(function (host, i) {
      servers.push(new mongo.Server(host, Number(ports[i]), self.options.server));
    });
github keystonejs / storage / lib / provider / mongodb.js View on Github external
var MongoClient = function MongoClient(config) {

	this._ensureValid(['database'], config);

	config = _.defaults(config, {
		host: 'localhost',
		port: 27017,
		options: {
			safe: true
		}
	});

	var db = this._db = new mongo.Db(config.database, new mongo.Server(config.host, config.port), config.options);

	MongoClient.super_.call(this, config, gfs(db, mongo));

};
github tangguangyao / stock / models / db.js View on Github external
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, Connection.DEFAULT_PORT, {}), {safe: true});
github catherinehwang / DJS / d.js View on Github external
exports.initialize = function (theServer, nowObj, erryOne) {
	server = theServer
	nowjs = nowObj
	everyone = erryOne
	
	module.exports = everyone.now;
	
	var usercoll;
	var mediacoll;
	var db = new Db('djs', new Server("localhost", 27017, {}), {native_parser:false});
	db.open(function(err, conn) {
		db = conn;
		db.collection('userinfo', function(err, coll) {
			usercoll = coll;
		});
		db.collection('mediainfo', function(err, coll) {
			mediacoll = coll;
		});
	});
	
	everyone.now.SbroadcastMedia = function (mId, roomId) {
		var self = this
		if (roomId != undefined) {
			mediacoll.findOne({_id: new db.bson_serializer.ObjectID(mId)}, function (err, doc) {
				var room = nowjs.getGroup(roomId);
				room.now.playback(doc);