Overview
To understand the difference between primary and secondary keys, you need to know that Cordial stores data as JSON objects in the following collections:
- Contact collection: stores data specific to a contact including channels, attributes, list membership, and cart items.
- Event (contact activities) collection: stores event data specific to messages (opens, clicks, etc.) or any custom-named event.
- Product collection: stores data from a product catalog.
- Orders collection: stores order data.
- Supplements collection: stores additional data (store locations, coupon codes, message content, and more) that doesn't fit into one of the above collections.
Primary key
A primary key is a piece of data, or value, that uniquely identifies each JSON object in our database. In Cordial, the primary key is typically the customer_id
. The primary key ensures that each JSON object can be easily retrieved and updated. Cordial gives you the option to choose the primary key or generate it automatically, in which case it will be the customer_id
.
Secondary key
A secondary key can be used to find a specific subset of data within a JSON object. Unlike a primary key, a secondary key does not have to be unique. Multiple JSON objects can have the same value for a secondary key, and each value can be associated with multiple JSON objects. Secondary keys are used to enable and enhance specific queries, which facilitates segmentation.
Example
In this example, let's say you have a JSON object in the contact collection with the following values:
-
customer_id
(primary key) email
first_name
last_name
gender
date_of_birth
purchase_history
website_behavior
The customer_id
is the primary key for this JSON object. If we want to look up the purchase history of a specific customer, we can use their customer_id to find that data.
But let's say you want to segment your customers by gender for a specific marketing campaign. To do this, you can create a secondary key using the gender value. This allows you to quickly find all the contacts that have a specific gender value (e.g., male
or female
) and use that information to shape your messaging.
Comments
0 comments
Please sign in to leave a comment.