[MB-7346] Documentation outdated in page http://www.couchbase.com/docs/couchbase-devguide-2.0/filter-extract-data.html Created: 04/Dec/12  Updated: 11/Dec/12  Resolved: 11/Dec/12

Status: Closed
Project: Couchbase Server
Component/s: documentation
Affects Version/s: 2.0-beta, 2.0-beta-2, 2.0
Fix Version/s: 2.0
Security Level: Public

Type: Bug Priority: Major
Reporter: Filipe Manana Assignee: kzeller
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   
The page at:

http://www.couchbase.com/docs/couchbase-devguide-2.0/filter-extract-data.html

Shows several documents with the _id and _rev fields. These meta data fields are no longer inlined in documents after DP4.

Also, the field "language" for design documents has no special meaning in Couchbase (unlike Apache CouchDB), being superfluous and confusing to users.

There's also a map function example with duplicated if conditional:

function(doc) {
if (doc.title) {
   if(doc.title) {
     emit(doc.title, null);
   }
  }
}

Finally, the following paragraph:

"As a best practice we want make sure that the fields we want to include in our index actually exist. Therefore we have our map function within a conditional: if (doc.age && doc.name). This ensures the fields exist in documents when we query the view and we therefore avoid a view failure when Couchbase Server generates the index."

Is not completely correct. If doc.age or doc.name don't exist in a document, using them as keys or values doesn't produce an error.
Undefined fields in JavaScript are serialized to a JSON null value.
What would produce an error would be something like referencing doc.name.length, when name isn't defined in the document.


 Comments   
Comment by kzeller [ 10/Dec/12 ]
Ok. I've updated the paragraph to say:

    <para>
      Here is how the map function appears when you provide full
      handling of all JSON document information:
    </para>

<programlisting>
function (doc, meta) {
  if (meta.type == "json" &amp;&amp; doc.title &amp;&amp; doc.date) {
    // Check if doc is JSON
    emit(doc.title, doc.date);
  } else {
    // do something with binary value
  }
}
</programlisting>
  
   <para> As a best practice we want make sure that the fields we want to emit in our index
   actually exist before we emit it to the index. Therefore we have our map function within a
   conditional: <literal>if (doc.title &amp;&amp; doc.date)</literal>. For instance,
   if we wanted to perform a views function
   that tried to reference <literal>doc.name.length</literal> we would get a null value if the
   field does not exist and the view function would fail. By checking for the field we avoid
   these potential types of errors.</para>


This will be available here later today: http://www.couchbase.com/docs/couchbase-devguide-2.0/filter-extract-data.html
Comment by kzeller [ 10/Dec/12 ]
See updated text/example.
Comment by Filipe Manana [ 11/Dec/12 ]
Karen, Thanks.

However this part:

For instance,
   if we wanted to perform a views function
   that tried to reference <literal>doc.name.length</literal> we would get a null value if the
   field does not exist and the view function would fail. By checking for the field we avoid
   these potential types of errors.</para>

Is still not correct. For that example (doc.name.length) we would not get null, but rather an "undefined reference" exception would be raised by the JavaScript engine. Doing "doc.name" is what would produce a null.

Comment by Filipe Manana [ 11/Dec/12 ]
See comment above.
Comment by kzeller [ 11/Dec/12 ]
I see, and will add this information. In the future for these types of issues, it would be more helpful if you not only call out the error, but also explain what happens to server behavior (does it crash, does it freeze, is it unable to handle other views in the design document, etc. and if there is a solution/workaround) This is truly the important information for customers/customer support not just errorname=XYZ appears.....


Thanks!
Comment by Filipe Manana [ 11/Dec/12 ]
Karen, I said what it happens, the JavaScript function will raise an exception.

As described in the wiki and other places, when that happens a log message is logged to mapreduce_errors.N file, referencing the error, document ID, bucket name, design document name, etc. This doesn't crash or freezes the server.
Generated at Sun Apr 20 02:32:55 CDT 2014 using JIRA 5.2.4#845-sha1:c9f4cc41abe72fb236945343a1f485c2c844dac9.