recipes/server/maker.js
2016-06-30 14:52:35 +01:00

63 lines
1.6 KiB
JavaScript

var nano = require('nano')('http://martind2000:1V3D4m526i@localhost:5984');
// clean up the database we created previously
nano.db.destroy('recipes', function () {
// create a new database
nano.db.create('recipes', function () {
// specify the database we are going to use
var recipes = nano.use('recipes');
// and insert a document in it
/* recipes.insert({ crazy: true }, 'rabbit', function(err, body, header) {
if (err) {
console.log('[alice.insert] ', err.message);
return;
}
console.log('you have inserted the rabbit.')
console.log(body);
});*/
recipes.insert(
{
"views": {
"titles": {
"map": function (doc) { emit(null, doc.title); }
}
}
}, '_design/titles', function (error, response) {
console.log("_design/titles added");
});
recipes.insert(
{
"views": {
"reducedView": {
"map": function (doc) { emit(null, [doc.title, doc.reduced]); }
}
}
}, '_design/reducedView', function (error, response) {
console.log("_design/reducedView added");
});
});
});
/**
* Created by Martin on 02/03/2016.
*/
/*
{
"getTagByKey": {
"map": function(doc) {
if (doc.tags.list.length > 0) {
for (var t = 0; t < doc.tags.list.length; t++) {
emit(doc._id, [doc.tags.list[t], doc.title]);
}
}
}
}
}
*/