Skip to content

Instantly share code, notes, and snippets.

{
"id": "lRkFyEuBLa7AnGGS1jfagQ",
"doc_type": "user",
"join_date": "2014-02-23 09:18:52 UTC",
"last_active": "2014-02-23 10:55:29 UTC",
"number_of_visits": 4227,
"origin": "GB",
"offers": [
"298-897-673",
"888-756-343",
function (doc, meta) {
if(meta.type == "json") {
if(doc.doc_type && doc.doc_type == "user") {
if(doc.origin) {
emit(doc.origin);
}
}
}
}
function (doc, meta) {
if(meta.type == "json") {
if(doc.doc_type && doc.doc_type == "user") {
if(doc.last_active && doc.origin) {
emit([doc.origin,dateToArray(doc.last_active)]);
}
}
}
}
function (doc, meta) {
if(meta.type == "json") {
if(doc.doc_type && doc.doc_type == "user") {
if(doc.join_date) {
emit(dateToArray(doc.join_date));
}
}
}
}
{
"id": "-JEVHOVwyze3I9u1G_JHhg",
"doc_type": "user",
"join_date": "2014-01-29 03:40:05 UTC",
"last_active": "2014-02-03 04:54:50 UTC",
"number_of_visits": 4768,
"origin": "RU"
}
require 'json'
require 'securerandom'
require 'couchbase'
couchbase = Couchbase.connect(:bucket => "users",:hostname => "localhost")
def generate_offers
offers = ['324-567-343','888-756-343','343-645-121','691-809-507','192-343-572','298-897-673']
number_of_offers = rand(1..3)
selected_offers = []