Skip to content

Searching

Upkar Lidder edited this page May 8, 2019 · 3 revisions

Searching using Map/Reduce

Search by country and reduce using _count

function (doc) {
  if(doc.country) {
    emit(doc.country, {"first_name":doc.first_name, "last_name":doc.last_name,"country":doc.country});
  }
}

Search by age and reduce using count to get a histogram

function (doc) {
  if(doc.age){
      emit(doc.age, doc.age);
  }
}

country and age

function (doc) {
  if(doc.country && doc.age) {
  emit([doc.country, doc.age], {"first_name":doc.first_name, "last_name":doc.last_name});
  }
}

Exercises

  1. List all users from Albania who are 30 year or less
  2. How many males and females in each country ?
  3. Return all users that do not have a postal_code
  4. List all users with country starting with B
Clone this wiki locally