Collection reference
A collection reference enables access to a collection of documents (NoSQL) or a table (SQL) in a database.
Collection basics
Creating a collection reference is straightforward – 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');
To get a reference to the users collection in database connector, pass a Connector ID as the second parameter. This ID can be found in the connectors section of the Squid Console:
const collectionRef = squid.collection<User>('users', 'YOUR_CONNECTOR_ID');
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 within that collection.
Next steps
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 connecting to 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 page on document references.