couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From CGS <cgsmcml...@gmail.com>
Subject Re: _design doc issue
Date Fri, 27 Jan 2012 04:08:06 GMT
Use single quota ( ' ) instead of escape character and double quota.(\").
For some reasons I don't know, the JSON parser is no capable of
interpreting \" as it should.

CGS




On Fri, Jan 27, 2012 at 3:48 AM, Stephan Bardubitzki <
stephan@bardubitzki.com> wrote:

> 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-**d5bca128d1fb98545691d78fa6aff9**bb",
>   "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.
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message