// Retrieve
var MongoClient = require('mongodb').MongoClient;
// Connect to the db
MongoClient.connect("mongodb://yourusername:yourpassword@yourserveraddress:yourport/yourdatabase", function(err, db) {
if(err) { return console.dir(err); }
db.createCollection('nodejs', function(err, collection) {});
var collection = db.collection('nodejs');
var doc1 = {'hello':'doc1'};
var doc2 = {'hello':'doc2'};
var lotsOfDocs = [{'hello':'doc3'}, {'hello':'doc4'}];
collection.insert(doc2, {w:1}, function(err, result) {});
collection.insert(lotsOfDocs, {w:1}, function(err, result) {});
});
2015-09-17
MongoDB using Node.js - Part 1
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment