Data Services

When you create a Kinvey Studio app, you connect it to a Kinvey backend app and environment to draw data from. On app level, you can manage backend collections and set up their fields. On view level, you can select from which collection the view draws data and how. And on component level, you can bind component elements to collection data.

The data collections provided by the backend can be Kinvey collections where data is stored in the cloud or a variety of external data sources connected to a Kinvey collection.

Switching the Backend

You can switch your Kinvey Studio app to use another Kinvey backend app environment at any time.

Pay special attention to the completeness of your collection set when switching backend environments. Not having parity between the source and target environments' collections may cause your app to malfunction. We recommend using the Kinvey Console app environment migration feature to ensure parity.

  1. Open your app in Kinvey Studio.
  2. In the left-side navigation, select the Settings tab.
  3. Use the Kinvey Application Environment field to select a different app environment from the backend app that you selected originally.

Managing Collections

Kinvey Studio allows you to do the most frequent collection actions such as creating and deleting. For less frequent actions, you need to go to Kinvey Console.

Syncing Collections

Collections can be created either in Kinvey Studio or using Kinvey Console. To ensure that you always see the latest collections in Kinvey Studio, use the sync function.

The sync function is one-way. Collection additions and deletions that you make in Kinvey Studio appear on the backend immediately. Additions and deletions made on the backend you must sync.

To sync the backend changes to Kinvey Studio:

  1. Open your app in Kinvey Studio.
  2. In the left-side navigation, select the Collections tab.
  3. In the left-hand toolbar, click the Sync Collections icon.

Adding Collections

Adding a collection creates an empty collection on the backend.

  1. Open your app in Kinvey Studio.
  2. In the left-side navigation, select the Collections tab.
  3. In the left-hand toolbar, click the Sync Collections icon to get the latest list of collection on the backend.
  4. In the same toolbar, click Add Collection.
  5. Give the collection a name and click Add Collection.

Deleting Collections

Deleting a collection deletes it along with its data from the backend. It also deletes any linked metadata created in Kinvey Studio.

  1. Open your app in Kinvey Studio.
  2. In the left-side navigation, select the Collections tab.
  3. In the list of collections, click the collection that you want to delete.
  4. Click the gear icon next to the collection name and select Delete.
  5. Confirm the deletion.

Editing Collection Fields

When creating an app, Kinvey Studio reads the first record of each available backend collection and tries to detect its field types. If a record is not available, Kinvey Studio only creates the system fields _id, _acl, and _kmd. Kinvey Studio sets the field type to object if it can't determine it as one of the following types: string, number, boolean, date. You may need to change the field types in case of unsuccessful detection or unavailable data.

The Collections tab also allows you to create new fields or make fields unavailable for the Kinvey Studio app. New fields are only stored as local metadata. They get created in the backend the first time your app tries to write a new entity that contains the field.

Including or Excluding Fields

You data may contain entity fields that you don't want the application to access. A good example are system fields like _acl, _kmd, and even _id, which doesn't require a custom value in the majority of cases.

To include or exclude fields:

  1. Open the application in Kinvey Studio.
  2. In the left-side navigation, click the Collections tab.
  3. Click the collection that you want to edit.
  4. Drag fields between the Excluded Fields and Included Fields lists to exclude or include fields respectively.
  5. In the left-hand toolbar, click Save.

Adding Fields

Any fields that you add in Kinvey Studio are only stored as local metadata. They get created in the backend the first time your app tries to write a new entity that contains the field.

To add a field:

  1. Open the application in Kinvey Studio.
  2. In the left-side navigation, click the Collections tab.
  3. Click the collection that you want to edit.
  4. Click Add Field in the Included Fields list.
  5. Select the new field that appears at the bottom of the list.
  6. In the Properties tab of Inspector, change the Name box to the value you want.
  7. In the left-hand toolbar, click Save.

Deleting Fields

Any fields that you delete in Kinvey Studio are only deleted from the local metadata. If the field still exists in a collection entity, it will reappear on the list on sync.

To delete a field:

  1. Open the application in Kinvey Studio.
  2. In the left-side navigation, click the Collections tab.
  3. Click the collection that you want to edit.
  4. Hover over a field name and then click the trash icon next to it.
  5. In the left-hand toolbar, click Save.

Renaming Fields

Take special care when renaming fields. If a field has been autodetected from an existing collection entity, renaming it will effectively create a new local field. The old field will reappear on the list as soon as you sync the collection.

To rename a field, see Editing Field Properties.

Editing Field Properties

Any field properties that you edit in Kinvey Studio only remain as local metadata.

To edit a field's properties:

  1. Open the application in Kinvey Studio.
  2. In the left-side navigation, click the Collections tab.
  3. Click the collection that you want to edit.
  4. Select the field that you want to edit.
  5. In the Properties tab of Inspector, change the values that you want.
  6. In the left-hand toolbar, click Save to save the changes.
Field nameDescription
NameTake special care when renaming a field. See Renaming Fields for details.
LabelThe display name of the field.
TypeSets field metadata that is required by certain view components.
RequiredWhen set, your app will not be able to write collection entities that do not have this field set.

Connecting Views to Data Services

After you have configured your collection on the Collections tab, you need to connect your views to them to actually use the data.

Depending on the view type, there are a couple of different ways to set the view's data service. In both cases, after you select a data service, you can bind components placed on the view to data stored in the selected data service.

To set the data service on view types that only use a single data service:

  1. Open the application in Kinvey Studio and then open the module where the view resides.
  2. In the Views pane on the left, select the view that you want to edit.
  3. In the Properties tab of Inspector, change Data Connections > Collection drop-down box to a backend collection.
  4. Depending on the view type, set any other properties that might need binding to collection entities.
  5. In the left-hand toolbar, click Save to save the changes to the view.

To set one or more data services on view types that can use multiple data services:

  1. Open the application in Kinvey Studio and then open the module where the view resides.
  2. In the Views pane on the left, select the view that you want to edit.
  3. In the Inspector on the right, find the View's Data Services area.
  4. Click Add to create a new data service.

    A new data service appears, automatically bound to the first available collection in alphabetical order.

  5. Click the data service entry to edit it in the Properties pane that appears below.

    • Collection: selects a backend collection
    • Name: names the data service with an arbitrary name
  6. Select a Result Type:

    • entity—Specifies that the data service is expected to return a single entity. Suitable when implementing the master-detail template.
    • collection—Specifies that the data service is expected to return multiple entities and allows you to specify a page size for paging purposes.
    • aggregation—Specifies that the data service is expected to return an aggregated value and allows you to specify a field to group by. Use only with prefedined Chart components (currently web-only). The component determines the aggregation function to use depending on the use case.
  7. Click Save.

  8. In the left-hand toolbar, click Save to save the changes to the view.

Filtering

When adding data service to detail or custom views, you have the option to filter the return data on a field from another data collection. The data service's result type must be set to entity or collection. The aggregation result type cannot be filtered.

To use a data service as an origin for a filter field, you need to set the data service's result type to entity.

Assume you have a master-detail view based on the sample vehicles collection. The detail view will normally show car details stored in vehicles, but you want to also show information from a dealerships collection—the name of the dealership that sold you the car. To implement this relation in Kinvey Studio, you would add the dealerships collection as a data service to the detail view and then filter it on its vehicles field with the id from the vehicles collection as received from the master view.

To create a filter:

  1. Add an origin.

    The origin is the data service that will feed filter values.

  2. Ensure that its Result Type is set to entity.

  3. Add an acceptor.

    The acceptor is the data service that you want to filter.

  4. Ensure that its Result Type is set to entity.

  5. Ensure that Filter Data Service is checked.
  6. In Entity Source, select the origin data service.

    Shown are only entity sources that have their Result Type set to entity.

  7. In Primary Key, select the origin field that contains the filter values.

  8. In Foreign Key, select the acceptor field that you want to filter on.

After you set up the filter, the acceptor data that relates to the respective origin data is available on the view.

Binding Hierarchical Data

To bind a component to hierarchical collection data like nested objects or arrays, use the dot notation in the component's Data property. In the meantime, ensure that the Result Type property of the parent view's data service is set to entity.

Assume that you are in the context of the sample automotive app. You want to list all the optional equipment on a car. You store that data as an options array of objects with each vehicles entry.

[
  {
    "vin": "GMC98765FTR5466",
    "year": "GMC98765FTR5466",
    "model": "Savana Cargo",
    "make": "GMC",
    "options": [
      {
        "name": "ACC",
        "installation": "manufacturer",
        "description": "Adaptive cruise control with emergency breaking."
      },
      {
        "name": "Roof rails",
        "installation": "dealership",
        "description": "Longitudinal roof rails for freighting purposes."
      }
    ]
  },
  ...
]

Let's say you are using the List View component on a Stack Layout to show the data. Take these steps to set it up the component:

  1. Start by adding vehicles as a Data Service to the parent view.
  2. In the data service's Result Type property, select entity.
  3. Select the List View on the canvas.
  4. In the Inspector, find the DATA > Data property and select $data.vehicles?.options from the drop-down list.

    Note that the options array will not be available for selection if the result type of the data service is set to collection or aggregation.

  5. Save the view.

For some components, such as Combo Box on web, you can select properties from nested object and bind them to Data Text Field and Data Value Field in the Inspector.

Related Resources

Kinvey Support Knowledge Base solutions: