Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var fs = require('fs');
- var mongo = require("mongodb");
- var config = JSON.parse(fs.readFileSync('./config.json'));
- var host = config.host;
- var port = mongo.Connection.DEFAULT_PORT;
- var db = new mongo.Db("Nodejs-introduction", new mongo.Server(host,port,{}));
- db.open(function(error){
- console.log("we are connected " + host + " : " + port );
- db.collection("user",function(error,collection){
- console.log("we have the collection");
- collection.insert({
- name:"jarvis"
- }, function(err,result){
- if(err) throw err;
- console.log(result);
- db.close();
- });
- });
- collection.insert({
- name: "jarvis"
- }, function(err,result){
- console.log(err);
- });
- collection.insert({
- name: "jarvis"
- }, function(err,result){
- if(err) throw err;
- console.log(result);
- db.close();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement