I am now using couchdb as my database , how to use dynamic variables as parameters in map functions in couch db?
Asked
Active
Viewed 1,013 times
0
-
The main principle of map-reduce procedure is that the map() function result can only depend on the document, because its calculated only once. Please explain what you are trying to accomplish, most probably you should be using show/list functions. – Marek Kowalski Sep 05 '13 at 11:36
2 Answers
1
You can't pass parameters to views in CouchDb. The views in many cases have already been built. You'll need to structure your views to handle the queries that you'll need.

WiredPrairie
- 58,954
- 17
- 116
- 143
-
Addition: you may build views as base and than use [list functions](http://guide.couchdb.org/draft/transforming.html) to transform them. List functions handles custom parameters from user's query, so they solves the problem. The downside is the full scan complexity of such queries in comparison to query the views with key params. – Kxepal Sep 08 '13 at 10:31
0
The map-component of views in couchdb are defined by you and included in the design doc. Then these functions can be reached through http://localhost:5984/yourDatabase/_design/doc/_view/yourViewFunction
The dynamic variables you might be looking for is passing a query with the url like this
http://localhost:5984/yourDatabase/_design/doc/_view/yourViewFunction?key=value-pairs-stacked-with-&(ampersand)
Then you can pass the _view/function startkey, endkey and a few others. Please have a read here for further studies.
Hope my answer made sense =) Good luck!

Pea-Pod
- 79
- 9
-
By using `key`, `startkey` and `endkey` params you queries view index, not passing variables into it. – Kxepal Sep 08 '13 at 10:28
-
1@Kxepal. I think you are absolutely right and mayhaps I should have pointed that out more clearly that it seems _to me_ that what Josemon is looking for is this. I did not want to write Josemon on the nose that I thought he might have confused expressions. I did it out of tact and good manners. But, you are right. – Pea-Pod Sep 08 '13 at 12:14