Client
The main TopK client for interacting with the TopK service. This client provides access to collections and allows you to perform various operations like creating collections, querying data, and managing documents.Constructor
Configuration object for the TopK client
ClientConfig
Configuration for the TopK client. This struct contains all the necessary configuration options to connect to the TopK API.Your TopK API key for authentication
The region where your data is stored. For available regions see: https://docs.topk.io/regions
Custom host URL (optional, defaults to the standard TopK endpoint)
Whether to use HTTPS (optional, defaults to true)
Retry configuration for failed requests (optional)
Methods
collections()
Returns a client for managing collections. This method provides access to collection management operations like creating, listing, and deleting collections.A client for managing collections
collection(name)
Returns a client for interacting with a specific collection.The name of the collection
A client for interacting with the specified collection
CollectionClient
Client for interacting with a specific collection. This client provides methods to perform operations on a specific collection, including querying, upserting, and deleting documents.get(ids, fields?, options?)
Retrieves documents by their IDs.Array of document IDs to retrieve
Optional array of field names to retrieve. If not specified, all fields are returned
Optional query options for consistency control
A promise that resolves to a map of document IDs to documents
count(options?)
Counts the number of documents in the collection.Optional query options for consistency control
A promise that resolves to the number of documents in the collection
query(query, options?)
Executes a query against the collection.The query to execute
Optional query options for consistency control
A promise that resolves to an array of matching documents
upsert(docs)
Inserts or updates documents in the collection.Array of documents to upsert. Each document must have an
_id fieldA promise that resolves to the LSN (Log Sequence Number) at which the upsert was applied
update(docs, failOnMissing?)
Updates documents in the collection. Existing documents will be merged with the provided fields. Missing documents will be ignored.Array of documents with fields to update. Each document must have an
_id fieldIf true, the operation will fail if any document is missing. Defaults to false
The LSN at which the update was applied. If no updates were applied, this will be empty
delete(expr)
Deletes documents from the collection by their IDs or using a filter expression.Either an array of document IDs or a logical filter expression
A promise that resolves to the LSN at which the delete was applied
Supporting Types
RetryConfig
Configuration for retry behavior when requests fail.Maximum number of retries to attempt before giving up
Total timeout for the entire retry chain in milliseconds
Backoff configuration for spacing out retry attempts
BackoffConfig
Configuration for exponential backoff between retry attempts.Base multiplier for exponential backoff (default: 2.0)
Initial delay before the first retry in milliseconds
Maximum delay between retries in milliseconds
QueryOptions
Options for query operations. These options control the behavior of query operations, including consistency guarantees and sequence number constraints.Last sequence number to query at (for consistency)
Consistency level for the query. Can be:
'indexed': Query returns results as soon as they are indexed (faster, eventual consistency)'strong': Query waits for all replicas to be consistent (slower, strong consistency)
ConsistencyLevel
Consistency levels for query operations.'indexed'- Indexed consistency: faster, eventual consistency'strong'- Strong consistency: slower, waits for all replicas