Can CouchDB query_params in replication filter take an array? -
i've got replication filters working great in couchdb when parameter string. however, i'm wondering if i'm able send in array instead. example, existing, working filter takes query_param user , can populated value "tony". i'd like, able check multiple users, such query_params
{ "users": [ "laura", "tony" ] }
i've tried in curl , {"error":"bad_request","reason":"invalid_json"}
. i'm not sure invalid json is.
the request via curl looks like:
curl -h 'content-type: application/json' \ -x post http://example.com:5984/_replicate \ -d '{"source":"http://example.com:5984/db1","target":"http://example.com:5984/db2", "filter":"repfilter/users", "query_params":{"users":["laura","tony"]}'
in filter code, check existence of document field userid
in users
array query params.
"users": "function(doc,req){ if(req.query.users.indexof(doc.userid) >= 0){return true;} return false; }"
is not possible in couch or doing wrong? should use comma-separated string instead?
i think best way accomplish array doing this:
?users="laura"&users="tony"
i'm not 100% positive how erlang parses type of querystring, if fails, comma-separated list going simpler:
?users="laura,tony"
just add following in fn:
var users = req.query.users.split(',');
Comments
Post a Comment