ArrayStorage
ArrayStorage is an abstract field type that other Array-related field types
can extend. Fields that use ArrayStorage include:
- EnumMultiple
- StructuredArray
Such fields have additional abilities built-in, that are not documented separately.
Filtering
You can filter the array by individual item values. Let's assume you have the
following items stored in the database:
await app.collections.cakes.suCreate({ ingredients: ["flour", "water", "carrot"], }); await app.collections.cakes.suCreate({ ingredients: ["carrot", "water", "flour"], }); await app.collections.cakes.suCreate({ ingredients: ["flour", "water", "eggs"], }); await app.collections.cakes.suCreate({ ingredients: ["flour", "salt"], });
Now, if you filter the cakes collection by a single value in the ingredients
field, it will return all items that contain that particular ingredient:
const { items: watery } = await app.collections.cakes .suList() .filter({ ingredients: "water" }) .fetch(); assert.strictEqual(watery.length, 3);
You can also filter by multiple ingredients. To do so, you provide a single
object as a filter. That object has to have one key (all, exact, any) with an
array value.
const { items: carrot_nonreverse } = await app.collections.cakes .suList() .filter({ ingredients: { exact: ["flour", "water", "carrot"], }, }) .fetch(); assert.strictEqual(carrot_nonreverse.length, 1); const { items: carrot_any_direction } = await app.collections.cakes .suList() .filter({ ingredients: { all: ["flour", "water", "carrot"], }, }) .fetch(); assert.strictEqual(carrot_any_direction.length, 2); const { items: eggs_or_salt } = await app.collections.cakes g .suList() .filter({ ingredients: { any: ["eggs", "salt"], }, }) .fetch(); assert.strictEqual(eggs_or_salt.length, 2);
File Metadata
File Metadata
- Mime Type
- text/plain
- Expires
- Sun, Nov 2, 17:26 (14 h, 14 m)
- Storage Engine
- blob
- Storage Format
- Raw Data
- Storage Handle
- 1029199
- Default Alt Text
- array-storage.remarkup (1 KB)