Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. var fs = require('fs');
  2.  
  3. var mongo = require("mongodb");
  4.  
  5. var config = JSON.parse(fs.readFileSync('./config.json'));
  6.  
  7. var host = config.host;
  8.  
  9. var port = mongo.Connection.DEFAULT_PORT;
  10.  
  11. var db = new mongo.Db("Nodejs-introduction", new mongo.Server(host,port,{}));
  12.  
  13. db.open(function(error){
  14. console.log("we are connected " + host + " : " + port );
  15.  
  16. db.collection("user",function(error,collection){
  17. console.log("we have the collection");
  18.  
  19. collection.insert({
  20. name:"jarvis"
  21. }, function(err,result){
  22. if(err) throw err;
  23.  
  24. console.log(result);
  25.  
  26. db.close();
  27. });
  28.  
  29. });
  30.  
  31. collection.insert({
  32. name: "jarvis"
  33. }, function(err,result){
  34. console.log(err);
  35. });
  36.  
  37. collection.insert({
  38. name: "jarvis"
  39. }, function(err,result){
  40. if(err) throw err;
  41.  
  42. console.log(result);
  43.  
  44. db.close();
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement