Add Data
POST
/api/collections/data/addThere are three ways to add data to a WorqDB Collection:
- Set the Data of a Document within a Collection, with an automatically generated document identifier or
docId
. - Add a Document with a custom
docId
to identify your document within a Collection. - Create an empty document with an automatically generated identifier, and assign data to it later. You can do this by using the
create
method and then theupdate
method later on.
Before you begin
See Get started with Create a Collection to create a Collection before you add data to it.
Set the Data of a Document within a Collection
:::info
You can read more about Data Object Documents in the Data Types section and how we identify the data types of the fields in the section.
:::
You can add data to a Collection by using the add
method. This method will create a new document with an automatically generated document identifier or docId
.
curl --request POST \
--url https://api.worqhat.com/api/collections/data/add \
--header 'Authorization: Bearer <API KEY>' \
--header 'Content-Type: application/json' \
--data '{
"collection": "Sample Collection",
"data": {
"name": "John Doe",
"Company": "Acme Corp",
"Login": 1697359974
}
}'
Add a Document with a custom docId
You can add data to a Collection by using the add
method. This method will create a new document with a custom docId
that you can use to identify your document within a Collection.
curl --request POST \
--url https://api.worqhat.com/api/collections/data/add \
--header 'Authorization: Bearer <API KEY>' \
--header 'Content-Type: application/json' \
--data '{
"collection": "Sample Collection",
"docId": "sampleDocumentId",
"data": {
"name": "John Doe",
"Company": "Acme Corp",
"Login": 1697359974
}
}'
Create an empty document with an automatically generated identifier, and assign data to it later
You can create an empty document with an automatically generated identifier, and assign data to it later by using the update
method. This method will create a new document with an automatically generated document identifier or docId
and the Document Creation Timestamp.
curl --request POST \
--url https://api.worqhat.com/api/collections/data/add \
--header 'Authorization: Bearer <API KEY>' \
--header 'Content-Type: application/json' \
--data '{
"collection": "Sample Collection",
"docId": "thisIsOptionalString",
"data": {}
}'
Request
This is optional. DocId is the document identifier. You can choose to add your own docId or we will generate a random string
{
"collection": "testdata2",
"data": {
"uid": "user123",
"orgId": "1fe0a9ac-617a-42e4-a376-37808b98fc99",
"Company": "subscription",
"count": 5,
"metadata": {
"name": "John Doe",
"age": 30,
"address": {
"street": "123 Main St",
"city": "New York",
"country": "USA"
}
}
},
"docId": "user123"
}
Request samples
Responses
{
"message": "Data added successfully",
"processingTime": 572.122042,
"processingId": "fdbbd720-faf2-4453-98e0-e7648cd7de5c"
}