MongoDB
MongoDB is a document-oriented NoSQL database. Hyperterse provides support for MongoDB using the official MongoDB Go Driver, enabling you to run find, findOne, insertOne, insertMany, updateOne, updateMany, deleteOne, deleteMany, aggregate, and countDocuments operations.
Connecting to your server
Section titled “Connecting to your server”MongoDB adapters use the standard MongoDB connection URI:
adapters: my_mongodb: connector: mongodb connection_string: 'mongodb://localhost:27017'For MongoDB Atlas or SRV records:
connection_string: 'mongodb+srv://user:pass@cluster.mongodb.net/mydb'Adapter options
Section titled “Adapter options”Configure connection pool and timeouts via adapter options:
adapters: production_db: connector: mongodb connection_string: 'mongodb://user:pass@host:27017/mydb' options: maxPoolSize: 50 minPoolSize: 5 connectTimeoutMS: 10000 serverSelectionTimeoutMS: 5000For a complete list of connection options, see the MongoDB Go Driver connection string options.
Setting up a database
Section titled “Setting up a database”It is very easy to set up a database for Hyperterse. You can use your existing MongoDB deployment or start one and wire it up to Hyperterse.
-
Start MongoDB
Start MongoDB using your preferred method:
Terminal window # Dockerdocker run -d -p 27017:27017 mongo:latest# macOS with Homebrewbrew services start mongodb-community# Or use MongoDB Atlas (cloud)# Create a free cluster and copy the connection string -
Configure Hyperterse
Add the MongoDB adapter to your configuration:
adapters:main_db:connector: mongodbconnection_string: 'mongodb://localhost:27017'options:maxPoolSize: 10For authenticated MongoDB:
connection_string: 'mongodb://user:password@localhost:27017/mydb'For MongoDB Atlas with TLS:
connection_string: 'mongodb+srv://user:pass@cluster.mongodb.net/mydb' -
Verify connection
Test the connection using the development server:
Terminal window hyperterse dev -f config.terseLook for a successful connection message:
INFO Connected to adapter: main_db
MongoDB queries in Hyperterse use JSON statements. The statement field contains a JSON object specifying the database, collection, operation, and any filters or options:
Find documents with filter and limit:
queries: find-users: use: main_db description: 'Find users by name' statement: | {"database":"mydb","collection":"users","operation":"find","filter":{"name":"{{ inputs.name }}"},"options":{"limit":10}} inputs: name: type: stringHyperterse supports all standard MongoDB operations including find, findOne, insertOne, insertMany, updateOne, updateMany, deleteOne, deleteMany, aggregate, and countDocuments. Use parameterized inputs with {{ inputs.name }} for dynamic values. For collections using ObjectId fields, pass them as {"$oid":"hexstring"} in filters and updates.
Supported operations
Section titled “Supported operations”- find – query documents (optional:
filter,optionswithlimit,sort,projection,skip) - findOne – single document (optional:
filter,optionswithsort,projection,skip) - insertOne – insert one document (
document) - insertMany – insert many documents (
documentsarray) - updateOne – update one document (
filter,update, optionaloptions.upsert) - updateMany – update many documents (
filter,update, optionaloptions.upsert) - deleteOne – delete one document (
filter) - deleteMany – delete many documents (
filter) - aggregate – aggregation pipeline (
pipelinearray) - countDocuments – count documents (
filter, optionaloptions.limit,options.skip)
Examples
Section titled “Examples”Find one document:
queries: get-user: use: main_db description: 'Get user by ID' statement: | {"database":"mydb","collection":"users","operation":"findOne","filter":{"_id":{"$oid":"{{ inputs.userId }}"}}} inputs: userId: type: stringInsert one document:
queries: create-user: use: main_db description: 'Create a user' statement: | {"database":"mydb","collection":"users","operation":"insertOne","document":{"name":"{{ inputs.name }}","email":"{{ inputs.email }}"}} inputs: name: type: string email: type: stringUpdate one document:
queries: update-user: use: main_db description: 'Update user email' statement: | {"database":"mydb","collection":"users","operation":"updateOne","filter":{"_id":{"$oid":"{{ inputs.userId }}"}},"update":{"$set":{"email":"{{ inputs.email }}"}}} inputs: userId: type: string email: type: stringDelete one document:
queries: delete-user: use: main_db description: 'Delete user by ID' statement: | {"database":"mydb","collection":"users","operation":"deleteOne","filter":{"_id":{"$oid":"{{ inputs.userId }}"}}} inputs: userId: type: stringAggregate:
queries: user-stats: use: main_db description: 'Count users by status' statement: | {"database":"mydb","collection":"users","operation":"aggregate","pipeline":[{"$group":{"_id":"$status","count":{"$sum":1}}}]}Performance
Section titled “Performance”Hyperterse does not limit MongoDB performance. Use indexes, projection, and appropriate limits in your statements. Configure maxPoolSize and minPoolSize in adapter options to tune connection pooling.
Troubleshooting
Section titled “Troubleshooting”Connection refused
Section titled “Connection refused”Verify MongoDB is running and reachable:
mongosh "mongodb://localhost:27017"Check firewall and network when connecting to a remote server or Atlas.
Authentication failed
Section titled “Authentication failed”Ensure the connection string includes the correct username and password (URL-encoded if they contain special characters):
connection_string: 'mongodb://user:password@host:27017/mydb'For Atlas, use the connection string from the Atlas UI (it includes auth and options).
TLS / Atlas
Section titled “TLS / Atlas”For MongoDB Atlas, use the mongodb+srv:// URI provided by Atlas. The driver handles TLS and discovery. If you use a custom certificate, refer to the MongoDB Go Driver TLS documentation.
Invalid statement JSON
Section titled “Invalid statement JSON”The query statement must be valid JSON. Ensure quotes are correct and that {{ inputs.x }} placeholders are inside quoted strings. After substitution, the connector parses the result as JSON; malformed JSON will return an error.