Dynamic variables in map function couch db

1k Views Asked by At

I am now using couchdb as my database , how to use dynamic variables as parameters in map functions in couch db?

2

There are 2 best solutions below

1
WiredPrairie On

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.

2
Pea-Pod On

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!