How to use the mongodb.MongoClient 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 CityWebConsultants / Iris / chat_modules / mongodb.js View on Github external
function () {
            dbClient = new MongoClient(new Server(exports.options.server, exports.options.port), function (err, db) {
                if (err) {
                    console.log("[SEVERE] Database connection failure!");
                    console.log(err);
                }
            });

            // Open connection
            dbClient.open(function (err, dbClient) {
                gdb = dbClient.db(exports.options.database_name);

                hook('hook_mongodb_ready', {}, function() {});
            });

        },
    hook_db_insert: {
github mongodb / node-mongodb-native / docs / reference / layouts / shortcodes / find-documents.html View on Github external
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

// Connection URL
const url = 'mongodb://localhost:27017';

// Database Name
const dbName = 'myproject';

const client = new MongoClient(url);

// Use connect method to connect to the Server
client.connect(function(err, client) {
  assert.equal(null, err);
  console.log("Connected correctly to server");

  const db = client.db(dbName);

  findDocuments(db, function() {
    client.close();
  });
});
github AbdullahAli / node-stream-to-mongo-db / src / Dev / localDevTester.js View on Github external
const clearDB = async () => {
  try {
    const dbConnection = await MongoDB.MongoClient.connect(config.dbURL);
    await dbConnection.dropDatabase();
    await dbConnection.close();
  } catch (error) {
    console.log(error);
  }
};
github cube-js / cube.js / examples / real-time-dashboard / index.js View on Github external
app.post('/collect', (req, res) => {
  console.log(req.body);
  const client = new MongoClient(process.env.MONGO_URL);
  client.connect((err) => {

    const db = client.db();
    const collection = db.collection('events');
    collection.insertOne({ timestamp:  new Date(), ...req.body }, ((err, result) => {
      client.close();
      res.send("ok");
    }))
  });
});
github maierfelix / POGOserver / src / db / mongo.js View on Github external
return new Promise((resolve) => {
    mongodb.MongoClient.connect(url, (error, db) => {
      if (error) {
        this.print("MongoDB " + error, 31);
        this.retry("Retrying again in ", () => this.setupConnection().then(resolve), 5);
        return void 0;
      } else {
        this.db.instance = db;
        this.loadCollection(CFG.MONGO_COLLECTION_USERS).then(() => {
          this.print(`\x1b[36;1mMongoDB\x1b[0m\x1b[32;1m connection established\x1b[0m`);
          resolve();
        });
      }
      db.on("close", (error) => {
        this.print("MongoDB " + error, 31);
        this.retry("Trying to reconnect in ", () => this.setupConnection().then(resolve), 5);
      });
    });
github RioBus / proxy / src / core / database / driver / mongodb / mongoDb.ts View on Github external
public constructor(dbConfig: any){
		var url: string;
		if(dbConfig.user!=="" && dbConfig.pass!=="")
			url = "mongodb://"+dbConfig.user+":"+dbConfig.pass+"@"+dbConfig.host+":"+dbConfig.port+"/"+dbConfig.dbName;
		else
			url = "mongodb://"+dbConfig.host+":"+dbConfig.port+"/"+dbConfig.dbName;
		var context: any = Sync.promise(MongoClient, MongoClient.connect, url);
		if(context instanceof Error) throw context;
		this.context = context;
	}
github hanpama / girin / packages / mongodb / src / module.ts View on Github external
constructor(configs: MongoDBModuleConfigs) {
    super();
    this.client = new MongoClient(configs.URL, configs.CLIENT_OPTIONS);
    this.dbName = configs.DBNAME || 'test';
  }
  async bootstrap() {
github juicycleff / ultimate-backend / libs / nest-multi-tenant / src / database / mongo / mongo-core.module.ts View on Github external
useFactory: async (connections: Map) => {
        const key = hash.sha1({
          uri,
          clientOptions,
        });
        if (connections.has(key)) {
          return connections.get(key);
        }
        const client = new MongoClient(uri, clientOptions);
        connections.set(key, client);
        return await client.connect();
      },
      inject: [getContainerToken(containerName)],
github rippinrobr / baseball-stats-db / js / load-managers-playoffs-record.js View on Github external
var getManagers = function( pipeObj, callback ) {
    var mongoClient = new MongoClient()
      ;

    mongoClient.connect( pipeObj.input.url, function( err, db ) {   
      db.collection( pipeObj.input.collection ).find({playoffs: {$exists:true} }, {managers:1, playoffs:1}).toArray(
        function( err, results ) {
          if (err) cb( err, pipeObj );
             
          pipeObj.data.push( results );
          pipeObj.prevStep += 1;
          callback( err, pipeObj );
          db.close();
         }); 
    });

  };
github Telefonica / alfalfa / example / lib / db.js View on Github external
'use strict';

const MongoClient = require('mongodb').MongoClient;
const config = require('./config');

const client = new MongoClient(config.get('db'));

module.exports = client;