/
setup.js
36 lines (27 loc) · 847 Bytes
/
setup.js
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
30
31
32
33
34
35
36
'use strict';
var mongojs = require('mongojs');
var config = require('./config');
var db = mongojs(config.DB);
var form = require('./test/data/form.json');
var template = require('./test/data/template.json');
function handleCallback(error, data) {
if (error) {
console.error(error);
} else {
console.log(data);
}
}
function addDocument(options, callback) {
var collection = db.collection(options.collection);
collection.insert(options.document, function(err, data){
if (err) {
return callback(err, null);
} else {
return callback(null, data);
}
});
}
db.createCollection('forms', handleCallback);
db.createCollection('formtemplates', handleCallback);
addDocument({collection:'forms', document:form}, handleCallback);
addDocument({collection:'formtemplates', document:template}, handleCallback);