Skip to content

Commit 8e115bb

Browse files
authored
Add documentation for Projections. Closes #135
1 parent 2384145 commit 8e115bb

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
@@ -141,6 +141,27 @@ Register a new middleware.
141141
* `query`: The query object being handled
142142
* `op`: The op being handled
143143

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

146167
`share.close(callback)`

0 commit comments

Comments
 (0)