I'm quite new to CouchDB and have to struggle with the following issue
using Futon:
In 'temporary view' this code does what I want to get out:
function(doc) {
var today = new Date();
var month = today.getMonth();
var room, chatrooms = [];
for ( room in doc.room ) {
if ( doc.room[room].duration === 'seasonal' ||
doc.room[room].duration === 'ones' ) {
if ( doc.room[room].start < doc.room[room].end ) {
if( doc.room[room].start <= month && doc.room[room].end >=
month ) {
chatrooms.push(doc.room[room]);
}
}
else {
if( doc.room[room].start >= month && doc.room[room].end >=
month ) {
chatrooms.push(doc.room[room]);
}
}
}
else {
chatrooms.push(doc.room[room]);
}
}
emit(doc._id, chatrooms);
}
However, if I add this to the _design doc Futon will not save the document.
FF says: JSON.parse: bad control character in string literal.
My _design doc looks like this:
{
"_id": "_design/chat-categories",
"_rev": "9-d5bca128d1fb98545691d78fa6aff9bb",
"views": {
"categories": {
"map": "function(doc) {
var today = new Date();
var month = today.getMonth();
var room, chatrooms = [];
for ( room in doc.room ) {
if ( doc.room[room].duration === \"seasonal\" ||
doc.room[room].duration === \"ones\" ) {
if ( doc.room[room].start <
doc.room[room].end ) {
if( doc.room[room].start <= month &&
doc.room[room].end >= month ) {
chatrooms.push(doc.room[room]);
}
}
else {
if( doc.room[room].start >= month &&
doc.room[room].end >= month ) {
chatrooms.push(doc.room[room]);
}
}
}
else {
chatrooms.push(doc.room[room]);
}
}
emit(doc._id, chatrooms);
}"
}
}
}
What do I miss?
Thanks.