Comfortable | Docs
  • Comfortable Documentation
  • Concepts
    • Content Repositories
    • Content Types
    • Documents
    • Assets
    • Content Tree
    • Collections
    • Webhooks
    • Team
    • Locales
  • APIs
    • RESTful API
      • Endpoints
      • API Reference
        • Sorting
        • Filters
        • Localisation
        • Fields
        • Includes
        • Search
      • Query Examples
        • Collections
        • Single Documents
        • Single Assets
        • Sorting
        • Filters
        • Includes
    • Image Manipulation
  • SDKs
    • JavaScript
      • Query Options
      • Query All Documents
      • Query a Collection
      • Query a Single Document
      • Query an Alias
      • Query an Asset
      • Example: Filters
      • Example: Sorting
    • Nuxt.js
    • PHP
      • Query All Documents
      • Query Single Document
      • Query Collection
      • Query an Alias
      • Query an Asset
      • Fulltext Search
      • Query by Fields
      • Query by Type
      • Query by Id
      • Query by Tags
  • Guides
    • Vue Blog Example
  • Legal
    • Legal Notice
    • Privacy Policy
Powered by GitBook
On this page
  1. SDKs
  2. JavaScript

Example: Filters

Use the following query option to apply filters:

filters

Type: Comfortable.Filter collect or reduce documents by certain field values

const api = Comfortable.api('<repository-api-id>', '<api-key>');

var options = {
    filters: new Comfortable.Filter()
        .addAnd('title', 'like', '%Hello%')
        .addAnd('date', 'greaterThan', '2018-07-04')
        .addOr('topNews', 'equal', true)
        /** filter by document id **/
        .addAnd('id', 'equals', '123123123432425', 'meta')
        /** filter blogPosts (contentType) by title **/
        .addAnd('title', 'like', '%Hello%', 'fields', 'blogPosts')
        
        // syntax
        // .addAnd(property: string(<id|title|...>), operator: string(<equals|like|...>), value: any, context: string(<fields|meta>), contentType: string(<*|contentTypeApiId>))
        // .addOr(property: string(<id|title|...>), operator: string(<equals|like|...>)), value: any, context: string(<fields|meta>), contentType: string(<*|contentTypeApiId>))
}

api.getDocuments(options)
  .then(result => {
    // futher implementation
  })
  .catch(err => {
    throw err;
  })

PreviousQuery an AssetNextExample: Sorting

Last updated 3 years ago