When the view contains Reduce function, and the reduce property is set to false in query filter, couchbase always returns only the first record. Since reduce=false is set, expecting it to return all record in the view.
Testing with ReactNative and react-native-couchbase-lite
Doc:
{
_id: 1,
year: 2017,
month: 11,
price: 100,
},
{
_id: 2,
year: 2017,
month: 12,
price: 80,
}
View (Map and Reduce):
map:function (doc) {
emit([year, month], {price});
}.toString(),
reduce: function (keys, values, rereduce) {
var result = values[0];
for(var i=0; i< values.length; i++){
result.total += parseFloat(values[i].price);
}
return result;
}.toString()
Query:
db: ‘db_name’,
ddoc: ‘doc_name’,
view: ‘view_name’,
include_docs: false,
reduce:false
Output: (Though view contains 2 records, it displays record as below. It shows it returns reduce (reduce:true) value. Looks ‘reduce’ parameter not obeys)
[{“doc”:null,“id”:null,“key”:null,“value”:{“price”:100,“total”:180}}]
Expected Output: (Since reduce is set to false, all records in view should returned). Does it is possible to achieve in CouchbaseLite?
Following is the output that returned by the view without reduce function and expecting the same when reduce is set to false.
[{“doc”:null,“id”:1,“key”:[“2017”,“11”],“value”:{“price”:100}}, {“doc”:null,“id”:2,“key”:[“2017”,“12”],“value”:{“price”:80}}]