Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Couchbase | Couchbase Single Server 1.x

Reduce on _id

2 replies [Last post]
  • Login or register to post comments
Mon, 07/25/2011 - 06:54
glen@sm
Offline
Joined: 07/25/2011
Groups: None

Hi,

I am indexing all members of a posted document so the following example will add two rows to the index (fieldA, fieldB)

{
"_id:",
"_rev":,
"posted": {
"fieldA": valA,
"fieldB": valB,
}
}

When valA == valB, I want to index both of them.

Problem: When I search for valA/valB, I don't want the example document to be returned twice.

In this scenario, the _id is unique, but how can I use that to resolve the problem?

Top
  • Login or register to post comments
Mon, 08/15/2011 - 10:26
jan
Offline
Joined: 02/15/2011
Groups: None

Hi,

you could only emit if the fields differ:

function(doc) {
  if(doc.fieldA && doc.fieldB) {
    if(doc.fieldA === doc.fieldB) { // emit once
      emit(doc.fieldA, null);
    } else { // emit twice
      emit(doc.fieldA, null);
      emit(doc.fieldB, null);
    }
  }
}

Alternatively, you could query your view with the ?limit=1 option so you only ever get one row back.

Cheers
Jan
--

Top
  • Login or register to post comments
Tue, 12/27/2011 - 15:47
marcgayzd
Offline
Joined: 11/19/2011
Groups: None

Buy klonopin online without a prescription Borneo Behave Buy Ambien withdraw scala Klonopin sextet cryosurgery

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