Like most databases, WorqDB, logically groups data as collections. You can use the createCollection method to create a collection. The method takes in the name of the collection as the first argument, and several optional configuration options as the second and third arguments.

The parameters that we can pass to the createCollection method are:

  • name - The name of the collection to create.
  • structure - An object containing the Schema of the collection. This is optional. If not provided, the collection will be created and the structure will be defined along the way.
  • defaultSort - An object containing the default sort order of the collection. This is optional. If not provided, the collection will be created and the default sort order will be defined along the way.

WorqDB is a NoSQL, document-oriented database. Unlike a SQL database, there are no tables or rows. Instead, you store data in documents, which are organized into collections.

Each document contains a set of key-value pairs. WorqDB is optimized for storing large collections of large documents.

All documents must be stored in collections. Documents can contain nested objects, which can include primitive fields like strings.

Collections and documents are created explicitly in WorqDB. You need to create a collection before you can add documents to it. Since WorqDB is schemaless, you can create a collection without specifying the structure of the documents it will contain. Also, WorqDB is a database that is optimized for storing large collections of large documents. Therefore, you need to explicitly declare if you are adding a new document to a collection or updating an existing document.

Creating a Collection

With a Defined structure

As we have proceeded ahead with a schemaless approach, we do not enforce any data types on the fields. However, you can still declare the data types for the fields during the collection creation. This will help you to keep track of the data types of the fields in your collection.

Here is a list of the Data Types that are automatically identified and data types that you have to declare explicitly during document creation.

Data TypeAutomatically IdentifiedExplicitly Declared
string
number
float
boolean
date❌ (Identified as a String)
timestamp❌ (Identified as an Integer)
json
array
geopoint❌ (Identified as an Array)
uuid
ip

You can read more about the Data Types in the Data Types section.

Here is an example of creating a collection with a defined structure:

curl --request POST \
  --url https://api.worqhat.com/api/collections/create \
  --header 'Authorization: Bearer <API KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "collection": "Sample Collection",
  "collectionSchema": {
    "Name": "string",
    "Phone": "number",
    "Metadata": "json",
    "User ID": "uuid"
  },
  "collectionSortBy": "Name"
}'

Try it out in the API Reference

View API Reference to Implement

Visit the API Reference to learn how to Create Collections in your projects. Get access to Sample Code, API Endpoints and run it right within the browser to test it out.

Without a Defined structure

You can also create a collection without defining the structure of the collection. This will allow you to add documents to the collection without having to define the structure of the collection beforehand. You can just keep on adding data in the form of Data Object Documents to the collection and we will keep defining the structure along the way.

You can read more about Data Object Documents in the Data Object Documents section and how we identify the data types of the fields in the Data Types section.

Here is an example of creating a collection without a defined structure:

curl --request POST \
  --url https://api.worqhat.com/api/collections/create \
  --header 'Authorization: Bearer <API KEY>' \
  --header 'Content-Type: application/json' \
  --data '{
  "collection": "Sample Collection"
}'

Try it out in the API Reference

View API Reference to Implement

Visit the API Reference to learn how to Create Collections in your projects. Get access to Sample Code, API Endpoints and run it right within the browser to test it out.