Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Server 2.0

Reduce functions _count, _sum, _stats not working

4 replies [Last post]
  • Login or register to post comments
Sun, 03/17/2013 - 06:21
Stag
Offline
Joined: 03/17/2013
Groups: None

Hey there, I'm trying to count something with:

function (doc, meta) {
  emit(meta.id, 1);
}

and the reduce function is just _count. _sum and _stats don't work either.

There are 3 items in the bucket but the result is:

Key: null
ID: undefined
Value: 3

Why?

Edit: My CB version is 2.0.0 community

Top
  • Login or register to post comments
Sun, 03/17/2013 - 07:44
joakimw
Offline
Joined: 09/13/2011
Groups: None

The result had "value: 3" and you had 3 items in the bucket...

Seems like _count is working just fine, or? ;)

Top
  • Login or register to post comments
Sun, 03/17/2013 - 10:26
Stag
Offline
Joined: 03/17/2013
Groups: None

It's supposed to count the appearances of meta.id. Basically means the result should be something like this:

Key: firstkey
Value: 1
 
Key: secondkey
Value: 1
 
Key: thirdkey
Value: 1

Top
  • Login or register to post comments
Mon, 03/18/2013 - 00:16
tgrall
Offline
Joined: 09/05/2012
Groups: None

Hello,

Are you passing a group level when querying your view?

When you use the a reduce function this is applied to a group of keys.
By default when you call the view you do not have any group selected so the reduce is done at the root level, so if you have 3 documents the count will be 3.

When querying your view you should pass a group level, for example:

&group_level=1

Let me know if this fix your issue.

Regards

__________________

Tug
@tgrall

Top
  • Login or register to post comments
Mon, 03/18/2013 - 13:33
Stag
Offline
Joined: 03/17/2013
Groups: None

Thank you very much dude, that works for me. Didn't think of that group thing.

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker