Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. // connect to mongodb
  2. var MongoClient = require('mongodb').MongoClient,
  3. f = require('util').format;
  4.  
  5. var user = encodeURIComponent('admin'),
  6. password = encodeURIComponent('123456'),
  7. authMechanism = 'DEFAULT',
  8. authSource = 'admin';
  9.  
  10. // connection url
  11. var url = f('mongodb://%s:%s@localhost:27017?authMechanism=%s&authSource=%s',
  12. user, password, authMechanism, authSource);
  13.  
  14. var db = null;
  15. MongoClient.connect(url, function(err, db) { //Here is line 20!
  16. if(err) {
  17. console.log('Unable to connect to the mongoDB server. Error:', err);
  18. }
  19. else {
  20. console.log('Connection established to', url);
  21. db = database // once connected, assign the connection to the global variable
  22. }
  23. })
  24.  
  25. Error: missing delimiting slash between hosts and options.
  26. at module.exports (/home/lixing/Dropbox/thesis/node_modules/mongodb/lib/url_parser.js:37:11)
  27. at connect (/home/lixing/Dropbox/thesis/node_modules/mongodb/lib/mongo_client.js:289:16)
  28. at Function.MongoClient.connect (/home/lixing/Dropbox/thesis/node_modules/mongodb/lib/mongo_client.js:113:3)
  29. at Object.<anonymous> (/home/lixing/Dropbox/thesis/server.js:20:13)
  30. at Module._compile (module.js:570:32)
  31. at Object.Module._extensions..js (module.js:579:10)
  32. at Module.load (module.js:487:32)
  33. at tryModuleLoad (module.js:446:12)
  34. at Function.Module._load (module.js:438:3)
  35. at Module.runMain (module.js:604:10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement