Skip to content

Instantly share code, notes, and snippets.

@sideshowcoder
Created April 14, 2014 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sideshowcoder/10636356 to your computer and use it in GitHub Desktop.
Save sideshowcoder/10636356 to your computer and use it in GitHub Desktop.
Unique account numbers via view in couchbase
# Get a number of unique account numbers via a map / reduce view
#
# foobar bucket contains:
#
# A = {"acct":"123456","name":"John Smith"}
# B = {"acct":"123456","name":"John Smith"}
# C = {"acct":"123457","name":"Jane Doe"}
#
# map:
#
# function (doc, meta) {
# if (doc.acct) {
# emit(doc.acct);
# }
# }
#
# and reduce:
#
# _count
#
require "couchbase"
cb = Couchbase.connect("http://localhost:8091/pools/default/buckets/foobar")
accts = cb.design_docs["test"].test(group: true).map { |doc| doc.key }
p accts # => ["123456", "123457"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment