1

Is there a way we could pass in values to a view function other than a key?

In the database I have a list of places with coordinates, and I want to get all the places within a distance from a point. So my view function should be able to access a radius value and a pair of coordinates, and inside the function I would calculate the distance of each place to the pair of coordinates and compare it to radius.

How can I do that with cradle or couchdb? Any help will do.

mabounassif
  • 2,311
  • 6
  • 29
  • 46
  • 1
    I don't understand: are you talking of the [map function of a view](http://wiki.apache.org/couchdb/HTTP_view_API); or of [document update validation function](http://wiki.apache.org/couchdb/Document_Update_Validation)? – Marcello Nuccio Feb 26 '12 at 11:03
  • map function of a view, the document update validation function only works if an object already exists in the database AFAIK – mabounassif Feb 26 '12 at 18:26
  • I think you should take the time to read "[The CouchDB Definitive Guide](http://guide.couchdb.org/draft/index.html)" and the wiki pages I've linked to. There's lot of confusion in what you are saying and I don't understand what you are saying. – Marcello Nuccio Feb 27 '12 at 10:08
  • I've looked it through, and I just couldn't figure out a way to pass in other variables to the query, that the view function depend on. What if I only wanted to extract a certain documents that contain a variable within the range of a separate external variable.... – mabounassif Mar 03 '12 at 05:55

1 Answers1

1

No, the only dynamic filter you can use for views is the key (or keys) query string parameter. The art of writing views is to create keys which allow you to filter the returned rows appropriately.

Even the way you've phrased your question isn't actually correct. The key isn't actually passed into the view function. The view function just returns rows with a key, and the view query allows you to return a subset of those rows based on a single key, multiple keys, or a range of keys.

Your problem sounds like it would be better done in your app code.

smathy
  • 26,283
  • 5
  • 48
  • 68