mabounassif
mabounassif

Reputation: 2341

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?

Upvotes: 6

Views: 2327

Answers (1)

Dominic Barnes
Dominic Barnes

Reputation: 28439

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)

Upvotes: 4

Related Questions