- Local API - Extremely fast, direct-to-database access
- REST API - Standard HTTP endpoints for querying and mutating data
- GraphQL - A full GraphQL API with a GraphQL Playground
You can also use queries within Access Control
functions.
Operators
The following operators are available for use in queries:And / Or Logic
In addition to defining simple queries, you can join multiple queries together using AND / OR logic. These can be nested as deeply as you need to create complex queries. To join queries, use theand or or keys in your query object:
find operation, it would translate to finding posts where either the color is mint OR the color is white AND featured is set to false.
Nested properties
When working with nested properties, which can happen when using relational fields, it is possible to use the dot notation to access the nested property. For example, when working with aSong collection that has an artists field which is related to an Artists collection using the name: 'artists'. You can access a property within the collection Artists like so:
Writing Queries
Writing queries in FrogBot is simple and consistent across all APIs, with only minor differences in syntax between them.Local API
The Local API supports thefind operation that accepts a raw query object:
GraphQL API
Allfind queries in the GraphQL API support the where argument that accepts a raw query object:
REST API
With the REST API, you can use the full power of FrogBot queries, but they are written as query strings instead:https://localhost:3000/api/posts?where[color][equals]=mint
To understand the syntax, you need to understand that complex URL search strings are parsed into a JSON object. This one isn’t too bad, but more complex queries get unavoidably more difficult to write.
For this reason, we recommend to use the extremely helpful and ubiquitous qs-esm package to parse your JSON / object-formatted queries into query strings:
Performance
There are several ways to optimize your queries. Many of these options directly impact overall database overhead, response sizes, and/or computational load and can significantly improve performance. When building queries, combine as many of these strategies together as possible to ensure your queries are as performant as they can be.Indexes
Build Indexes for fields that are often queried or sorted by. When your query runs, the database will not search the entire document to find that one field, but will instead use the index to quickly locate the data. This is done by addingindex: true to the Field Config for that field: