Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Database
  3. var MongoClient = require('mongodb').MongoClient;
  4. var db;
  5.  
  6. // Initialize connection once
  7. MongoClient.connect("mongodb://localhost:27017/maindb", function(err, database) {
  8.   if(err) return console.error(err);
  9.  
  10.   db = database;
  11.   console.error("Connected to db");
  12. });
  13.  
  14. // Insert
  15. var item = [{"Item" : "val"} { "Item" : "val" }];
  16. db.collection('orders').insert(item, function(err, request) {
  17.     console.log('Inserted.');
  18. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement