Projections

Some types support exposing a projection of a real collection, with a specified set of allowed fields.

Currently, only json0 supports projections.

Once configured, the projected collection looks just like a real collection – except documents only have the fields that have been specified.

Operations on the projected collection work, but only a small portion of the data can be seen and altered.

Usage

Projections are configured using backend.addProjection(). For example, imagine we have a collection users with lots of information that should not be leaked. To add a projection names, which only has access to the firstName and lastName properties on a user:

backend.addProjection('names', 'users', {firstName: true, lastName: true})

Once the projection has been defined, it can be interacted with like a “normal” collection:

const doc = connection.get('names', '123')
doc.fetch(() => {
  // Only doc.data.firstName and doc.data.lastName will be present
});