Question : Mongo connect db
Answered by : adi
1 mongo # connects to mongodb://127.0.0.1:27017 by default
2 mongo --host <host> --port <port> -u <user> -p <pwd> # omit the password if you want a prompt
3 mongo "mongodb://192.168.1.1:27017"
4 mongo "mongodb+srv://cluster-name.abcde.mongodb.net/<dbname>" --username <username> # MongoDB Atlas
Source : https://www.mongodb.com/developer/quickstart/cheat-sheet/ | Last Update : Sat, 08 Jan 22
Question : Connect mongodb server
Answered by : md-emdadullah
const { MongoClient } = require("mongodb");
const connectionString = process.env.ATLAS_URI;
const client = new MongoClient(connectionString, { useNewUrlParser: true, useUnifiedTopology: true,
});
let dbConnection;
module.exports = { connectToServer: function (callback) { client.connect(function (err, db) { if (err || !db) { return callback(err); } dbConnection = db.db("sample_airbnb"); console.log("Successfully connected to MongoDB."); return callback(); }); }, getDb: function () { return dbConnection; },
};
Source : https://www.mongodb.com/languages/express-mongodb-rest-api-tutorial | Last Update : Tue, 20 Sep 22