Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameters to map functions in CouchDb

I wonder if we could pass variables as parameters to a map function in CouchDb.

Practically, I have a database with coordinates of places, and I only want to map/reduce the places that are within reach of a point. How could I do that? I want something like:

function(doc, x, y, radius) {
  if (doc.x - x)^2 + (doc.y - y)^2 < radius^2 {
    emit(doc._id, doc);
  }
}

How can we do that in CouchDb?

like image 759
mabounassif Avatar asked Oct 09 '22 12:10

mabounassif


1 Answers

You have 3 options:

  1. Use GeoCouch since you're doing geo-spatial queries
  2. Write up separate view indexes for each of your locations
  3. Use a list function on a view that maps all your relevant documents (you can pass parameters via querystring to the list function)
like image 134
Dominic Barnes Avatar answered Oct 13 '22 12:10

Dominic Barnes