Yes, I agree that's strange.
I use Couch in another app and never had that issue, although I do have
a similar (but not the same) reduce.
_count won't work, as I return a summary, based on several fields of the
document. The reduce returns three values, not just a count of the docs
in the view.
------------------------------------------------------------------------
*With best regards,*
Kiril Stankov,
CEO
This Email disclaimer
<http://open-net.biz/emailsignature.html> is integral part
of this message.
On 28.9.2016 г. 20:33, Robert Samuel Newson wrote:
> It's very curious that compaction fixes this, I can't think how that makes
> any sense.
>
> It seems the built-in (and much faster) _count reduce function will do what
> you are doing here, could you compare that?
>
> I note as an aside that your 'total' value will be meaningless, it'll just be
> the length of whatever array couchdb last handed you, which is an arbitrary
> thing.
>
> B.
>
>> On 28 Sep 2016, at 16:47, Kiril Stankov <[email protected]> wrote:
>>
>> Sure. See below.
>>
>> The view filters documents from all docs, the reduce gives statistics
>> depending on values.
>> Very simple.
>>
>> An interesting thing is that when it breaks vals.length always equals 2.
>>
>> BTW - just happened again, second time today. Compact of the view always
>> fixes this.
>>
>> View:
>>
>> function(doc) {
>> if(doc.status!='deleted' && (!doc.endUser || doc.forwarded) &&
>> !doc.pID) {
>> emit(null, [(doc.status=='new'),(doc.status=='forwarded')]);
>> }
>> }
>>
>> Reduce:
>>
>> function(keys, vals, rereduce) {
>> // reduce function
>>
>> var result = {'new':0, 'total':vals.length,forwarded:0};
>> for(var i = 0; i < vals.length; i++) {
>> result.new += vals[i][0]?1:0;
>> result.forwarded+= vals[i][1]?1:0;
>> }
>> return result;
>> }
>>
>> Thanks!
>>
>>
>> On 28.9.2016 г. 18:16, Jan Lehnardt wrote:
>>> Heya,
>>>
>>> Can you share the view code?
>>>
>>> Best
>>> Jan
>>> --
>>>
>>>> On 28 Sep 2016, at 15:38, Kiril Stankov <[email protected]> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I just saw this again.
>>>> Reduce didn't work until compacting the View.
>>>>
>>>> This starts to be a serious problem.
>>>> Any help or suggestion how to debug this will be appreciated.
>>>>
>>>> Thanks!
>>>>
>>>> ------------------------------------------------------------------------
>>>> *With best regards,*
>>>> Kiril Stankov,
>>>>
>>>> On 24.9.2016 г. 20:43, Kiril Stankov wrote:
>>>>> Hi all,
>>>>>
>>>>> I use CouchDb 1.6 and have a view with reduce (same on all databases),
>>>>> which returns some statistics.
>>>>>
>>>>> Suddenly, today, it started returning strange things, and I think that
>>>>> the problem was that vals.length was returning 0. There are only few
>>>>> dozens docs in this DB.
>>>>> I have a replication DB where everything worked fine, checked that the
>>>>> code is exactly the same.
>>>>>
>>>>> After compacting the views on the first DB, it also started showing the
>>>>> correct values.
>>>>>
>>>>> Any idea what could cause this? View corruption? There are plenty of
>>>>> resources (disk, memory) on the host machine.
>>>>>
>>