-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
29 lines (25 loc) · 902 Bytes
/
Copy pathsetup.js
File metadata and controls
29 lines (25 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//Run once to set up Mongo database and collections for Crudite to operate on.
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');
var ObjectId = require('mongodb').ObjectID;
var url = 'mongodb://localhost:27017/crudite';
var insertDocument = function(db, callback) {
db.collection('recipes').insertOne( {
"title" : "Stone Soup",
"author" : "Joel Tanzi",
"ingredients" : [ "1 stone", "4 cups water" ],
"prep_time" : "15",
"instructions" : "1. Boil water. 2. Add stone. 3. Boil for 15 minute and serve.",
"contains" : [ "stone", "water" ]
}, function(err, result) {
assert.equal(err, null);
console.log("Inserted a document into the recipes collection.");
callback(result);
});
};
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
insertDocument(db, function() {
db.close();
});
});