SapphireDb logo SapphireDb

Limit data - Take/Skip prefilter

You can use the take and skip prefilters to control the queried data
With skip you omit the given count of values.
With take you limit the queried data.
With first you can query only the first element.
With last you can query only the last element.

Note that the usage of the prefilter types Take, Skip, Select, Count, First and Last will require the collection data to always get queried from the database on every change. Keep that in mind when creating performance critical tasks.

Limit

In this example only the first 5 values are queried.

\f:(typescript:demo.component.ts) export class DemoComponent implements OnInit {\n \tvalues$: Observable<any>;\n \tconstructor(private db: SapphireDb) { }\n\n \tngOnInit() {\n \t\tthis.values$ = this.db.collection<any>('entries')\n \t\t\t.take(5)\n \t\t\t.values();\n \t}\n }
null

Skip

In this example the first 5 values are omitted.

\f:(typescript:demo.component.ts) export class DemoComponent implements OnInit {\n \tvalues$: Observable<Entry[]>;\n \tconstructor(private db: SapphireDb) { }\n\n \tngOnInit() {\n \t\tthis.values$ = this.db.collection<Entry>('entries')\n \t\t\t.skip(5)\n \t\t\t.values();\n \t}\n }
null

First/Last

In this example the first and last value is selected.

\f:(typescript:demo.component.ts) export class DemoComponent implements OnInit {\n \tvalueFirst$: Observable<Entry>;\n \tvalueLast$: Observable<Entry>;\n \tconstructor(private db: SapphireDb) { }\n\n \tngOnInit() {\n \t\tthis.valueFirst$ = this.db.collection<Entry>('entries')\n \t\t\t.first()\n \t\t\t.values();\n\n \t\tthis.valueLast$ = this.db.collection<Entry>('entries')\n \t\t\t.last()\n \t\t\t.values();\n \t}\n }
First: null
Last: null
Note that the operation last cannot be performed on database side and will be evaluated in your backend application. Be careful when using it.
Continue with select prefilter

This website uses Google Analytics. If you want to disable it just unselect the option: