Created
April 14, 2014 10:36
-
-
Save sideshowcoder/10636356 to your computer and use it in GitHub Desktop.
Unique account numbers via view in couchbase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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