Page tree
Skip to end of metadata
Go to start of metadata

Use this strategy to get documents from the database by specified formula.

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 used
  • selectQuery(String query): selection formula to apply to the database; mandatory. This is exactly the same you would write as view selection formula in Notes.

 

router.GET('topics/cat1cat2') {
 strategy(DOCUMENTS_BY_FORMULA) {
   selectQuery('SELECT Form=\"MainTopic\" & @Contains(Categories;\"category1\":\"category2\")')
 }
 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)'
 mapJson 'categories', json:'categories', type:'ARRAY_OF_STRING'
} 

 

URL parameters:

  • count: number or records to return, default is 10
  • start: 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/cat1cat2?count=5 will return all documents from database, that match the selection formula.

Returned JSON:

{
  "entries": [
        {
      "date_created":"2017-03-03T18:28+00:00",
      "author":"Martin Jinoch",
      "id":"54502859C07299C7C12580D8006404F4",
      "categories": [
        "category1"
      ]
    },
        {
      "date_created":"2017-03-11T13:11+00:00",
      "author":"Martin Jinoch",
      "id":"DCEFCAE41C0C9815C12580E0004BD296",
      "categories": [
        "category1",
        "category2"
      ]
    }
  ],
  "start":1,
  "total":2,
  "count":2
}