Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.0-beta, 2.0-beta-2, 2.0
-
Fix Version/s: 2.0
-
Component/s: documentation
-
Security Level: Public
-
Labels:None
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.
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.
Activity
MC Brown
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Assignee | MC Brown [ mccouch ] | Karen Zeller [ kzeller ] |
Farshid Ghods
made changes -
| Fix Version/s | 2.0 [ 10114 ] |
Karen Zeller
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
Karen Zeller
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
Filipe Manana
made changes -
| Resolution | Fixed [ 1 ] | |
| Status | Closed [ 6 ] | Reopened [ 4 ] |
Karen Zeller
made changes -
| Status | Reopened [ 4 ] | Resolved [ 5 ] |
| Resolution | Fixed [ 1 ] |
Karen Zeller
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
<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" && doc.title && 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 && 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