no problem…
DATA:
{
"_id": "MENU_10",
"_rev": "4-9a7d86f53125771a892d0b2d8189f75d",
"week": 0,
"day": 0,
"grpsortno": 13,
"component": {
"alternatedesc": "Tee"
},
"compsortno": 7,
"mealId": 1,
"stations": [],
"type": "MENU",
"savedat": "20170126135918"
},
{
"_id": "MENU_11",
"_rev": "4-470fbcc5099a8e568f94ea410ecc7286",
"week": 0,
"pkid": 11,
"day": 0,
"grpsortno": 13,
"component": {
"alternatedesc": "Kakao"
},
"compsortno": 13,
"mealId": 1,
"stations": [],
"type": "MENU",
"savedat": "20170126135919"
}
MAP FUNCTION:
function(doc) {
if (doc.type && (doc.type === 'MENU')) {
var mealId = 0;
if (doc.mealId) {
mealId = doc.mealId;
}
if (doc.type === 'MENU') {
if (doc.stations.length === 1) {
dietGrId = doc.stations[0];
}
}
emit([doc.type, mealId, doc.week, doc.day, dietGrId], doc);
}
};
CURL:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "keys": [ ["MENU", 1, 4, 4, 0], ["MENU", 1, 0, 0, 0], ["MENU", 1, 4, 4, 8], ["MENU", 1, 0, 0, 8] ] }' 'http://172.16.31.230:5984/servtouch962afde00917196b/_design/mainApp/_view/getMenu'
i’m creating the DESIGN DOCUMENT also over REST, as well as in version 1.1.0:
var docDesignMainApp = {
"_id": "_design/mainApp",
"language": "javascript",
"views": {
"getByStationRoom": {
"map": "function(doc) { if (doc.type && doc.type == 'TRAN' && doc.TRAN.PATIENT.station && doc.TRAN.PATIENT.room ) { emit([doc.TRAN.PATIENT.station.id, doc.TRAN.PATIENT.room], doc); }}"
},
"getByPaidDiet": {
"map": "function(doc) { if (doc.type && doc.type == 'TRAN' && doc.TRAN && doc.TRAN.DIET.pkid && doc.TRAN.DIET.diets) { for (var idx = 0; idx < doc.TRAN.DIET.diets.length; idx++) { emit([doc.TRAN.DIET.pkid, doc.TRAN.DIET.diets[idx].validFromNum, doc.TRAN.DIET.diets[idx].meal.sortno], {\"mealId\":doc.TRAN.DIET.diets[idx].meal.id, \"dietidx\":idx}); } } }"
},
"getByTypeSorted": {
"map": "function(doc) { if (doc.type) { var sortno = 0; var type = doc.type; if (doc.sortno) {sortno = doc.sortno;} if (type === 'TRAN') { type = type + '_' + doc.TRAN.PATIENT.name.toUpperCase(); } emit([type, sortno], doc); }}"
},
"getMenu": {
"map": "function(doc) { if (doc.type && (doc.type === 'MENU' || doc.type === 'MENUCOMPONENT' || doc.type === 'DIETMEALPROFIL')) { var dietGrId = 0; var mealId = 0; if (doc.mealId) { mealId = doc.mealId; } if (doc.dietGrId) { dietGrId = doc.dietGrId; } if (doc.type === 'MENU') { if (doc.stations.length === 1) { dietGrId = doc.stations[0]; } } emit([doc.type, mealId, doc.week, doc.day, dietGrId], doc); } }"
}
},
"filters": {
"deviceFilter": "function(doc, req){if (doc._deleted) {return true;} if (doc.type && doc.type.lastIndexOf('OUT') == (doc.type.length - 3)) {return false;} if (doc.type && doc.type == 'SERVERADDRESS') {return false;} if (doc.deviceId && req.query.deviceId && doc.deviceId == req.query.deviceId) { return true; } if (doc.deviceUUID && req.query.deviceUUID && doc.deviceUUID == req.query.deviceUUID && doc.type == 'DEVICE') { return false; } if (doc.couchapp) { return false; } if (doc.deviceId && doc.deviceId == '*') { return true; } return false;}",
"newsFilter": "function(doc, req){if (doc._deleted) {return false;} if (doc.type && doc.type == 'NEWS' ) { return true; } return false;}"
},
"couchapp": {
"manifest": [
"couchapp.json",
"filters/",
"filters/deviceFilter.js",
"filters/newsFilter.js",
"language",
"views/",
"views/getByPaidDiet/",
"views/getByPaidDiet/map.js",
"views/getByStationRoom/",
"views/getByStationRoom/map.js",
"views/getByTypeSorted/",
"views/getByTypeSorted/map.js",
"views/getMenu/",
"views/getMenu/map.js"
],
"signatures": {
},
"name": "Basic CouchApp",
"objects": {
},
"description": "CouchApp with changes feed and form support."
}
};
var optionsDesignMainApp = {
dbName: that.deviceinfo.databasenamedevice,
success: function (data) {
callback(data);
},
error: function (status) {
callback(status);
}
};
saveSingleDoc(docDesignMainApp, optionsDesignMainApp);
thanks in advance!