Skip to content

Commit c0e2fee

Browse files
authored
Merge pull request #154 from curran/patch-7
Add documentation for Projections
2 parents 987719e + f8741f3 commit c0e2fee

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ Register a new middleware.
142142
* `query`: The query object being handled
143143
* `op`: The op being handled
144144

145+
### Projections
146+
147+
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.
148+
149+
`addProjection(name, collection, fields)`
150+
Configure a projection.
151+
152+
* `name` The name of the projected collection.
153+
* `collection` The name of the existing collection.
154+
* `fields` A map (object) of the allowed fields in documents.
155+
* Keys are field names.
156+
* Values should be `true`.
157+
158+
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:
159+
160+
```js
161+
share.addProjection('users_limited', 'users', { name:true, profileUrl:true });
162+
```
163+
164+
Note that only the [JSON0 OT type](https://github.com/ottypes/json0) is supported for projections.
165+
145166
### Shutdown
146167

147168
`share.close(callback)`

0 commit comments

Comments
 (0)