davidsavoie1:collection-fns

v0.2.1Published last year

collection-fns

Functions used on Meteor collections to provide extra functionnality like performant and elegant hooks and inter-collections joins.

Documentation still in progress...

API

fetchList and fetchOne

Replaces Coll.find().fetch() and Coll.find().fetchOne(), enhancing result with collection joins and augments.

fields options argument is greatly improved when joins are defined.

  • If object with only own fields, acts as the basic collection behavior;
  • If undefined or thruthy value, fetch all own fields;
  • If join fields are specified, the joined collections will be recursively fetched with the same fields principles;
  • If ONLY join fields are specified, all own fields will also be returned;
  • If own fields AND join fields are specified, only those own fields will be fetched, along with the recursively fetched join documents;

Example

1join(Parents, {
2  children: {
3    Coll: Children,
4    on: ["_id", "parentId"],
5  },
6});
7
8join(Children, {
9  toys: {
10    Coll: Toys,
11    on: [["toyIds"], "_id_"],
12  },
13});
14
15fetchList(
16  Parents,
17  {},
18  {
19    fields: {
20      name: 1, // own -> only `name` from parents included with `children`
21      children: {
22        // join only -> all own `children` fields
23        toys: { color: 1, forAge: 1 }, // only own limited `toys` fields
24      },
25    },
26  }
27);