Collection reference
A collection reference is a reference to a collection of documents (NoSQL) or a row of a table (SQL) in a database.
You can use a collection reference to read or write data to the collection. A collection can refer to a table in a relational database or a collection in a NoSQL database.
Collection basics
Creating a collection reference is straightforward. You can simply call the collection method on the squid
object and
provide the collection name as the first parameter.
A collection reference acts as a pointer to a specific collection in a database. It allows you to access and
manipulate data stored in that collection. This code snippet shows how to get a reference to the users
collection in Squid's built-in database:
const collectionRef = squid.collection<User>('users');
Alternatively, you can get a reference to the users collection in a specific integration by passing an integrationId
as the
second parameter. The integrationId
can be found in the integrations section of the Squid Console.
This feature allows you to work with data from external integrations easily:
const collectionRef = squid.collection<User>('users', 'integrationId');
One additional collection attribute is the reference ID. This ID is a string that uniquely
identifies the collection reference. To access the refId
, simply use:
collectionRef.refId;
Once you have a reference to a collection, you can perform various operations on it, such as querying and manipulating data, or getting a specific document reference within that collection.
Additional collection information
Collections in Squid provide a unified way to interact with data stored in different databases. Whether you're working with Squid's built-in database or integrating with external resources, collection references streamline data management.
Adding or deleting data from a collection cannot be done at the collection level and must be done at the document level. To learn more, continue on to the next page on document references.