Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var http = require('http');
- var MongoClient = require('mongodb').MongoClient;
- var url = "mongodb://localhost:27017/mydb";
- MongoClient.connect(url, function(err, db) {
- if (err) throw err;
- db.createCollection("customers", function(err, res){
- if (err) throw err;
- console.log("Collection created!");
- db.close();
- });
- });
- MongoClient.connect(url, function(err, db) {
- if (err) throw err;
- var myobj = {name: "Company Inc", address: "Highway 37"};
- db.collection("customers").insertOne(myobj, function(err, res){
- if (err) throw err;
- console.log("1 document inserted");
- db.close();
- });
- });
- MongoClient.connect(url, function(err, db) {
- if (err) throw err;
- db.collection("customers").findOne({}, function(err, result){
- if (err) throw err;
- console.log(result.name);
- db.close();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement