Use this strategy to get documents from the view by key. The view will be searched by the first sorted column.
Allowed method
- GET
Parameters:
databaseName(String databaseName)
: name of the database to read data from, use "server!!path/database.nsf
" format; when omitted, current database is usedviewName(String viewName)
: name of the view; mandatorykeyVariableName(String keyVariableName)
: name of the variable name in route to read key from; mandatorymode("exact")
: when present, sets strict key matching. Usesview.
getAllDocumentsByKey(key, true). If this parameter is omitted, usesview.
getAllDocumentsByKey(key, false) - default
Let's assume our database has view called (ByTopic)
, that contains first sorted column displaying Topic
field.
Notice the {filterValue}
part of the first line bellow. This is placeholder for where SmartNSF expects to read parameter value for keyVariableName
from, see line 4.
router.GET('topics/filter/{filterValue}') { strategy(DOCUMENTS_FROM_VIEW_BY_KEY) { viewName('(ByTopic)') keyVariableName('filterValue') } mapJson 'id', json:'id', type:'STRING', isformula:true, formula:'@DocumentUniqueID' mapJson 'date_created', json:'date_created', type:'DATETIME', isformula:true, formula:'@Created' mapJson 'topic', json:'topic', type:'STRING' mapJson 'author', json:'author', type:'STRING', isformula:true, formula:'@Name([CN]; @Author)' }
URL parameters:
count
: number or records to return, default is 10start
: position in the view to start from, default value is 1
With route defined above, URL http://server.name/path-to/db.nsf/xsp/.xrest/topics/filter/test
will return all documents from view (ByTopic)
with field Topic
starting with "test". If mode('exact')
was specified, it would return just those document with Topic "test".
For example, if only one document matches this filter, we'll get this JSON:
{ "entries": [ { "date_created": "2017-03-03T18:28+00:00", "author": "Martin Jinoch", "id": "54502859C07299C7C12580D8006404F4", "topic": "test" } ], "start": 1, "total": 1, "count": 1 }
Related articles