Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {MongoClient} = require('mongodb');
- const {dbUrl, dbPort, dbName} = require('dbconfig');
- // 'mongodb://localhost:27017/AppDatabase'
- const connectionUrl = `mongodb://${dbUrl}:${dbPort}/${dbName}`;
- MongoClient.connect(connectionUrl, (err, db) => {
- if(err){
- return console.log('Unable to connect to mongodb server');
- }
- console.log('Connected to mongodb Server');
- db.collection('Users').insertOne({
- firstName: 'Lakmal',
- lastName: 'Caldera'
- }, (err, res) => {
- if(err){
- console.log('Unable to insert user');
- }
- console.log(JSON.stringify(res.ops, undefined, 2));
- });
- // Close connection
- db.close();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement