Collection Management

Manage collections in R2R

Occasionally this SDK documentation falls out of date, cross-check with the automatically generated API Reference documentation for the latest parameters.

A collection in R2R is a logical grouping of users and documents that allows for efficient access control and organization. Collections enable you to manage permissions and access to documents at a collection level, rather than individually.

R2R provides a comprehensive set of collection features, allowing you to implement efficient access control and organization of users and documents in your applications.

Collection permissioning in R2R is still under development and as a result the API will likely evolve.

Collection Creation and Management

Create a Collection

Create a new collection with a name and optional description:

1const createCollectionResponse = await client.createCollection(
2 "Marketing Team",
3 "Collection for marketing department"
4);
5const collectionId = createCollectionResponse.results.collection_id; // '123e4567-e89b-12d3-a456-426614174000'

Get Collection Details

Retrieve details about a specific collection:

1const collectionDetails = await client.getCollection(collectionId);

Update a Collection

Update a collection’s name or description:

1const updateResult = await client.updateCollection(
2 collectionId,
3 "Updated Marketing Team",
4 "New description for marketing team"
5);

List Collections

Get a list of all collections:

1const collectionsList = await client.listCollections();

User Management in Collections

Add User to Collection

Add a user to a collection:

1const userId = '456e789f-g01h-34i5-j678-901234567890'; // This should be a valid user ID
2const addUserResult = await client.addUserToCollection(userId, collectionId);

Remove User from Collection

Remove a user from a collection:

1const removeUserResult = await client.removeUserFromCollection(userId, collectionId);

List Users in Collection

Get a list of all users in a specific collection:

1const usersInCollection = await client.getUsersInCollection(collectionId);

Get User’s Collections

Get all collections that a user is a member of:

1const userCollections = await client.getCollectionsForUser(userId);

Document Management in Collections

Assign Document to Collection

Assign a document to a collection:

1const documentId = '789g012j-k34l-56m7-n890-123456789012'; // Must be a valid document ID
2const assignDocResult = await client.assignDocumentToCollection(documentId, collectionId);

Remove Document from Collection

Remove a document from a collection:

1const removeDocResult = await client.removeDocumentFromCollection(documentId, collectionId);

List Documents in Collection

Get a list of all documents in a specific collection:

1const docsInCollection = await client.getDocumentsInCollection(collectionId);

Get Document’s Collections

Get all collections that a document is assigned to:

1const documentCollections = await client.getDocumentCollections(documentId);

Advanced Collection Management

Collection Overview

Get an overview of collections, including user and document counts:

1const collectionsOverview = await client.collectionsOverview();

Delete a Collection

Delete a collection:

1const deleteResult = await client.deleteCollection(collectionId);

Pagination and Filtering

Many collection-related methods support pagination and filtering:

1// List collections with pagination
2const paginatedCollections = await client.listCollections(10, 20);
3
4// Get users in a collection with pagination
5const paginatedUsers = await client.getUsersInCollection(collectionId, 5, 10);
6
7// Get documents in a collection with pagination
8const paginatedDocs = await client.getDocumentsInCollection(collectionId, 0, 50);
9
10// Get collections overview with specific collection IDs
11const specificCollectionsOverview = await client.collectionsOverview(['id1', 'id2', 'id3']);

Security Considerations

When implementing collection permissions, consider the following security best practices:

  1. Always use HTTPS in production to encrypt data in transit.
  2. Implement the principle of least privilege by assigning the minimum necessary permissions to users and collections.
  3. Regularly audit collection memberships and document assignments.
  4. Ensure that only authorized users (e.g., admins) can perform collection management operations.
  5. Implement comprehensive logging for all collection-related actions.
  6. Consider implementing additional access controls or custom roles within your application logic for more fine-grained permissions.

For more advanced use cases or custom implementations, refer to the R2R documentation or reach out to the community for support.