Skip to content

Collections

It is useful to aggregate Persons in your organization into groups.

Whether the groups are departments, sub-divisions, or even your own customers, groups are helpful to stay organized.

In our parlance, a group of persons is called a Collection

Let us now create a Collection

Create a Collection

A Collection has a name and a description. It also has an id, but that is auto-assigned by the system.

Let's create a new Collection with the name My Groovy Collection, and with the description Groovy or Boring:

CollectionBase my_collection_base{"My Groovy","Groovy or Boring"};
Collection my_collection = sdk.collections.create(my_collection_base);
cout << my_collection.id;

Above lines of code will create a collection called “my_collection”. You're on your way to more impressive feats!

List Collections

Our SDK allows you to list all collections you ever created. To do so, you can execute the following code in your next adventurous exploration:

Options op;
CollectionCount all_collections = sdk.collections.list(op);

This should return an “all_collections” object of type CollectionCount. The “count” attribute of the object indicates the number of collections and the “collection” attribute of the objects is a vector of collection object(s) with particulars such as “name” and “description” in it.

Filtering Collections

Details of the options object can be used to filter the collection.

The skip parameter tells the system to skip the specified number of records from the beginning of matched records. The take parameter tells the system to get the specified number of records from the skip position. if take is 20, then the system will return 20 records (unless there are less than 20 from the skip position). The order parameter specifies an order (ascending or descending). The search parameter filters collections that contain the search string in either their name or description.

Options op;
op.skip=0;
op.take=20;
op.order = SortOrder::ASCENDING;
op.search=”My”;
CollectionCount all_collections = sdk.collections.list(op);

These parameters can help developers implement paging and sorting in a front end application.

Getting a specific Collection

You can get a collection by its id:

Collection my_new_collection= sdk.collections.get(my_collection.id);

Updating a Collection

You can update a Collection either after creating it, or after getting it (through sdk.collections.get() or through sdk.collections.list()):

Create:

CollectionBase my_collectionbase{"My Groovy Collection", "Groovy or Boring"};
Collection my_collection = sdk.collections.create(my_collectionbase);

Get:

Collection my_collection= sdk.collections.get(my_collection.id);

As long as my_collection is a valid reference to a collection, you can update it like so:

my_collection.name = "My Speedy Collection";
my_collection = sdk.collections.update(my_collection);

Deleting a specific Collection

If you know the id of a collection, you can delete is like so:

string deleted_id= sdk.collections.delete_collection(my_collection.id);