diff --git a/README.md b/README.md index ebdf2a661..5c4085163 100644 --- a/README.md +++ b/README.md @@ -141,6 +141,27 @@ Register a new middleware. * `query`: The query object being handled * `op`: The op being handled +### Projections + +ShareDB supports exposing a *projection* of a real collection, with a specified (limited) set of allowed fields. Once configured, the projected collection looks just like a real collection - except documents only have the fields you've requested. Operations (gets, queries, sets, etc) on the fake collection work, but you only see a small portion of the data. + +`addProjection(name, collection, fields)` +Configure a projection. + + * `name` The name of the projected collection. + * `collection` The name of the existing collection. + * `fields` A map (object) of the allowed fields in documents. + * Keys are field names. + * Values should be `true`. + +For example, you could make a `users_limited` projection which lets users view each other's names and profile pictures, but not password hashes. You would configure this by calling: + +```js +share.addProjection('users_limited', 'users', { name:true, profileUrl:true }); +``` + +Note that only the [JSON0 OT type](https://github.com/ottypes/json0) is supported for projections. + ### Shutdown `share.close(callback)`