couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yves S. Garret" <>
Subject Am I understanding this correctly?
Date Sat, 03 Aug 2013 01:55:44 GMT
This is the piece of Javascript code that I'm working with:

function(doc) {
  if('name' in doc && 'albums' in doc) {
    doc.albums.forEach(function(album) {
      var key = album.title ||;
      var value = {by:, album: album};

      emit(key, value);
      //emit(key, key);

Now, this is my interpretation of how I view this code.
- The function checks if there is a name and an albums field in the doc.
- Then, using the doc, it accesses the list of albums and executes for each
element in the list a
- That method accepts one element -- by design -- and only one element.
 That element is the
individual value that's stored in the list.  In this case, the format of
the list is assumed to be uniform and known in advance (but this is not
guaranteed and would need extra checking to take into
- In the function, the first variable is created by checking either
album.title or and
selecting the one that is not null (if both are null, then you have a
problem, but would assign to the
key a null).
- The value is created in a similar fashion by returning a tuple.
- The results are outputted.

Is my understanding of this correct?  Did I read the code correctly?

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