function (key, values, rereduce) {
// This is a built-in count reduce
if (rereduce) {
var result = 0;
for (var i = 0; i < values.length; i++) {
result += values[i];
}
return result;
} else {
return values.length;
}
}
models/my_couchbase_model.rb
class MyCouchbaseModel.rb < Couchbase::Model
view :my_view
end
controllers/my_controller.rb
def index
count = MyCouchbaseModel.my_view
puts count
# #<Couchbase::View:0x007fa880b42c80>
# => nil
end
It looks like count is nil.
How could I get the reduced result and its value?
Am I doing something wrong here?
Why don’t you just use _count in the reduce.js function? Also, you don’t need to emit meta.id as the key, since it always gets sent over in non-reduced cases (and in reduced it doesn’t matter anyways here)
when you say puts count it will print the object to STDOUT by calling to_s method on it. Here in Couchbase::View this method will output the object itself, just like you call puts count.inspect.
I think that because when include_docs specified, it tries to fetch the document body using its ID, and obviously there no id attribute in the reduced results