How to use the mongodb.MongoClient.connect 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 TheDrone7 / Wumpi / src / providers / mongodb.js View on Github external
async init() {
    const connection = mergeDefault(
      {
        conString: `mongodb://127.0.0.1:27017/WumpiDB`
      },
      this.client.options.providers.mongodb
    );

    // If full connection string is provided, use that, otherwise fall back to individual parameters
    const connectionString = connection.conString;

    const mongoClient = await Mongo.connect(
      connectionString,
      mergeObjects(connection.options, { useNewUrlParser: true, useUnifiedTopology: true })
    );

    this.db = mongoClient.db(connection.db);
  }
github TechEmpower / FrameworkBenchmarks / frameworks / JavaScript / nodejs / handlers / mongodb-raw.js View on Github external
const h = require('../helper');
const async = require('async');
const MongoClient = require('mongodb').MongoClient;
const collections = {
  World: null,
  Fortune: null
};
MongoClient.connect('mongodb://tfb-database/hello_world?maxPoolSize=5', (err, db) => {
  // do nothing if there is err connecting to db

  collections.World = db.collection('world');
  collections.Fortune = db.collection('fortune');
});


const mongodbRandomWorld = (callback) => {
  collections.World.findOne({
    id: h.randomTfbNumber()
  }, (err, world) => {
    world._id = undefined; // remove _id from query response
    callback(err, world);
  });
};
github parse-community / parse-server / spec / GridStoreAdapter.spec.js View on Github external
.then(() => {
        return MongoClient.connect(databaseURI)
          .then(client => {
            const database = client.db(client.s.options.dbName);
            // Verify the existance of the fs.files document
            return database
              .collection('fs.files')
              .count()
              .then(count => {
                expect(count).toEqual(0);
                return { database, client };
              });
          })
          .then(({ database, client }) => {
            // Verify the existance of the fs.files document
            return database
              .collection('fs.chunks')
              .count()
github jembi / openhim-core-js / test / utils.js View on Github external
export function getMongoClient () {
  const url = config.get('mongo:url')
  return MongoClient.connect(encodeMongoURI(url), { useNewUrlParser: true })
}
github scottie1984 / mongo-func / src / connection.js View on Github external
return new Promise((resolve, reject) => {
    const connectionString =
      typeof connectionObject === "string"
        ? connectionObject
        : connectionObject.connectionString;
    const options =
      typeof connectionObject === "string"
        ? {}
        : R.omit(["connectionString"], connectionObject);
    let hasConnection = R.pick([connectionString], connectionPool);
    if (R.keys(hasConnection).length !== 0) {
      resolve(connectionPool[connectionString]);
    } else {
      MongoClient.connect(connectionString, options, (err, db) => {
        if (err) {
          reject(err);
        } else {
          connectionPool[connectionString] = db;
          resolve(db);
        }
      });
    }
  });
}
github gwilken / ariadne-io / cloud_service / model / mongo.js View on Github external
connect: function() {

      MongoClient.connect('mongodb://127.0.0.1:27017/ariadneIO', function(err, db) {

        if(err) console.log(err);

          console.log("Connected successfully to mongodb");



          mongo.db = db;
          mongo.collection = db.collection('data');
        });
    }
};
github SamyPesse / blini / src / Connection.js View on Github external
this._connection = new Promise(function(resolve, reject) {
                MongoClient.connect(infos, function(err, db) {
                    if (err) {
                        reject(err);
                    } else {
                        that.db = db;
                        resolve();
                    }
                });
            });
        }
github autonomoussoftware / ethereum-transaction-indexer / shared / src / db / mongo.js View on Github external
const createClientFor = url =>
  MongoClient.connect(url, { useNewUrlParser: true })
github MysteryPancake / Discord-Lyrebird / web / lyreweb.js View on Github external
} else if (req.query.state) {
				res.send("Query parameter <code>code</code> is required!");
			} else {
				res.send("Query parameters <code>code</code> and <code>state</code> are required!");
			}
		} else {
			res.send("Query parameters <code>code</code> and <code>state</code> are required!");
		}
	});
	app.listen(process.env.PORT || 8080, function() {
		logger.info("WEBSITE READY FOR ACTION!");
	});
}

const MongoClient = require("mongodb").MongoClient;
MongoClient.connect(process.env.MONGODB_URI, { useNewUrlParser: true }, function(error, dbClient) {
	if (error) {
		logger.error(error);
	} else {
		logger.info("CONNECTED TO DATABASE FROM WEBSITE!");
		const db = dbClient.db("lyrebird");
		connected(db);
	}
});