Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. const {MongoClient} = require('mongodb');
  2. const {dbUrl, dbPort, dbName} = require('dbconfig');
  3.  
  4. // 'mongodb://localhost:27017/AppDatabase'
  5. const connectionUrl = `mongodb://${dbUrl}:${dbPort}/${dbName}`;
  6.  
  7. MongoClient.connect(connectionUrl, (err, db) => {
  8. if(err){
  9. return console.log('Unable to connect to mongodb server');
  10. }
  11. console.log('Connected to mongodb Server');
  12.  
  13. db.collection('Users').insertOne({
  14. firstName: 'Lakmal',
  15. lastName: 'Caldera'
  16. }, (err, res) => {
  17. if(err){
  18. console.log('Unable to insert user');
  19. }
  20. console.log(JSON.stringify(res.ops, undefined, 2));
  21. });
  22.  
  23. // Close connection
  24. db.close();
  25. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement