Important
Helios features are now enabled during weekly update windows and are no longer directly tied to SingleStore engine releases. Refer to the release notes to view the latest features available in your Helios cluster.
Getting Started with SingleStore Kai
On this page
You can run MongoDB® queries on your SingleStore Kai ("the API") enabled clusters from MongoDB® clients/tools after performing these minimal steps:
-
Ensure that the prerequisites are met.
-
Enable the API endpoint for your cluster.
-
Access the API using supported tools/applications.
Disclaimer:
SingleStore is not a MongoDB® partner.
Prerequisites
-
A cluster group running SingleStore version 8.
5 or later. -
Run the following command to check the version:
SELECT @@memsql_version;
-
-
A SingleStore Kai-enabled cluster.
Refer to Enable the API for more information. -
Any MongoDB® client that uses the MongoDB® wire protocol or standard MongoDB® driver that supports the
loadBalancedmode.
Enable the API
To enable the API for your SingleStore Helios cluster, perform the following tasks:
-
On the Cloud Portal, select Create New > Cluster.
-
On the Create New Cluster page, enter or select the configuration settings as applicable.
-
Under Settings, enable the MongoDB® Compatible Endpoint API toggle switch.
-
Select Create Cluster.
The API is now enabled for your cluster.
Note: The following global compatibility configuration variables are automatically set when the API is enabled for a cluster:
-
json_:compatibility_ level '8.0' -
data_:conversion_ compatibility_ level '8.0' -
regexp_:format 'advanced'
If any of these variables cannot be set to the values specified above for a cluster, the API rejects any user authentication requests.
Access the API
A SingleStore Kai-enabled cluster has two different endpoints:
-
mongodb:// -
mysql://
For example:
-
mongodb://<user>:<password>@svc-XXXX.svc.singlestore.com:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true -
mysql://svc-XXXX.svc.singlestore.com:3306
Connect to the mongodb:// endpoint to run MongoDB® queries.
Clients/applications must connect to the API in load-balanced mode.loadBalanced=true in the connection string, the API rejects the authentication request with an explanatory error message.
You can also connect to your MongoDB® instance via AWS PrivateLink.
Manage Users and Permissions
To access a cluster's mongodb:// endpoint, a user must have the EXECUTE permission to the cluster database.
The following example shows how to grant the EXECUTE permission to a user:
GRANT EXECUTE ON cluster.* TO joe;
Refer to Manage Database Users for more information.
Kai Shell
The Kai Shell feature allows you to run MongoDB® queries on the Cloud Portal on a SingleStore Kai-enabled cluster.
Access the Kai Shell
To access the Kai Shell on the Cloud Portal, on the left navigation pane, select Editor > Open Kai Shell.
-
Create a SingleStore Kai-enabled cluster on the Cloud Portal.
Once the cluster is deployed, proceed to the next step. -
On the left navigation pane, select Editor > Open Kai Shell.
-
From the dropdown list at the top, select your cluster.
You can now run MongoDB® commands on your cluster using this shell. For example, run the following commands to insert a document in a collection named exampleCollection, and then view the contents of this collection: use dbTestdb.exampleCollection.insert({ _id: 1, message: "Hello there!"})db.exampleCollection.find()[ { _id: 1, message: 'Hello there!' } ]
Refer to Examples for CRUD examples.
Supported Tools
You can connect to your SingleStore Kai-enabled cluster's mongodb:// endpoint using the following tools:
-
Kai Shell (on the Cloud Portal)
-
Any MongoDB® client that uses the MongoDB® wire protocol or standard MongoDB® driver.
Here are a few examples: -
Mongoose.
js -
Prisma
-
Spring Boot
You can also connect to SingleStore Kai in load-balanced mode via various application development tools using the following MongoDB® drivers:
|
Language/Tool |
Driver |
Version |
|---|---|---|
|
C |
1. | |
|
C++ |
3. | |
|
C# / . |
2. | |
|
Go |
1. | |
|
Java |
4. | |
|
Kotlin |
4. | |
|
PHP |
1. | |
|
Python |
3. | |
|
Ruby |
2. | |
|
Rust |
2. | |
|
Scala |
4. | |
|
Swift |
1. |
Connect with MongoDB® Shell mongosh
To connect using the mongosh shell, use the following command:
mongosh "mongodb://<username>@<host>:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true"
For example:
mongosh "mongodb://admin@svc-XXXX.svc.singlestore.com:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true"
At the next prompt, enter the password to access the API endpoint.
Connect with MongoDB® for Visual Studio Code Extension
To connect to the API endpoint from Visual Studio Code, perform the following tasks:
-
Install the MongoDB® for VS Code extension.
-
On the navigation pane, select the MongoDB icon.
-
Under Connections, select Add Connection.
-
Under Connect with Connection String, select Connect.
-
Enter the connection string in the following format:
mongodb://<username>:<password>@<host>:27017/?authMechanism=PLAIN&tls=true&loadBalanced=true
Once the connection is successful, a Connected to: <host>:27017 message is displayed along with a MongoDB connection successful popup message.
Examples
The following examples perform CRUD operations using the API endpoint.
Create a Database
The following command creates a database named dbExample.
use dbExampleshow dbs
mongo 0.00 B
dbExample 0.00 B
information_schema 0.00 BCreate a Collection and Insert Documents
Run the following command to create a collection named exampleCollection and add multiple documents to this collection:
db.exampleCollection.insertMany( [{ _id: 1, Code: "xv1f", Qty: 45 },{ _id: 2, Code: "nm3w", Qty: 30 },{ _id: 3, Code: "qoma", Qty: 20 },{ _id: 4, Code: "hr3k", Qty: 15 } ] )
{ acknowledged: true, insertedIds: { '0': 1, '1': 2, '2': 3, '3': 4 } }Read Values from a Collection
The following command returns all the documents stored in exampleCollection:
db.exampleCollection.find()
[
{ _id: 1, Code: 'xv1f', Qty: 45 },
{ _id: 2, Code: 'nm3w', Qty: 30 },
{ _id: 3, Code: 'qoma', Qty: 20 },
{ _id: 4, Code: 'hr3k', Qty: 15 }
]Update a Collection
The following example updates the first document in exampleCollection where Code equals "xv1f":
db.exampleCollection.updateOne({ Code: "xv1f" },{ $set: { Qty: 40 } })
{
acknowledged: true,
insertedId: null,
matchedCount: 1,
modifiedCount: 1,
upsertedCount: 0
}db.exampleCollection.find()
[
{ _id: 1, Code: 'xv1f', Qty: 40 },
{ _id: 2, Code: 'nm3w', Qty: 30 },
{ _id: 3, Code: 'qoma', Qty: 20 },
{ _id: 4, Code: 'hr3k', Qty: 15 }
]The following example updates all the documents in exampleCollection where Qty is less than or equal to 25.
db.exampleCollection.updateMany({ Qty: {$lte: 25 } },{ $set: { Comment: "Restock required" }, $inc: { Qty: -10 } })
{
acknowledged: true,
insertedId: null,
matchedCount: 2,
modifiedCount: 2,
upsertedCount: 0
}db.exampleCollection.find()
[
{ _id: 1, Code: 'xv1f', Qty: 40 },
{ _id: 2, Code: 'nm3w', Qty: 30 },
{ _id: 3, Code: 'qoma', Qty: 10, Comment: 'Restock required' },
{ _id: 4, Code: 'hr3k', Qty: 5, Comment: 'Restock required' }
]Delete a Document
The following command deletes all the documents from exampleCollection that match the specified condition:
db.exampleCollection.deleteMany({ Comment: "Restock required", Qty: { $lt: 10 } })
{ acknowledged: true, deletedCount: 1 }Last modified: