Skip to content
Go back

MongoDB Atlas Setup Guide (Free-tier)

To build a “Sovereign Oracle”—an AI that owns its intelligence—we need a storage layer that is as flexible as the human mind and as persistent as a blockchain.

When dealing with Nostr relays, we are essentially drinking from a firehose of JSON data. Traditional SQL databases would choke on this variety. MongoDB is our choice because it speaks JSON natively. Below is the blueprint for setting up your permanent intelligence layer using MongoDB Atlas.

Building a Sovereign Oracle: The Complete Guide to MongoDB Atlas for kheAI

1. Why MongoDB for an AI MVP?

Before we click buttons, let’s talk strategy. Why are we here?

2. Provisioning Your Cloud Cluster

We’ll use MongoDB Atlas to get off the ground quickly.

  1. Deploy a Free Tier:
    1. Head to MongoDB Atlas.
    2. Cluster Name: Cluster0 (Standard for MVPs).
    3. Cloud Provider: AWS.
    4. Region: Singapore (ap-southeast-1) (Choose the region closest to your users or your server for lowest latency).
  2. Create Your Database User:
    • Username: kheai_db_user
    • Password: Use a strong, generated string. Avoid special characters like @ or : inside the password, as they can break the connection URI.
  3. Network Access (The “Gatekeeper”):
    • During development, go to Network Access > Add IP Address.
    • Select Allow Access From Anywhere (0.0.0.0/0).
    • Warning: This is for the MVP phase. Once you go live, restrict this to your server’s specific IP address.

3. Mastering the Connection String

This is where most newbies get tripped up. There are two “formats” for connection strings. You will likely see both in your journey, but one is superior.

This is the clean, short version. Use this for Node.js 3.6+ and modern Meteor setups.

mongodb+srv://kheai_db_user:YOUR_PASSWORD@cluster0.xnv0qyc.mongodb.net/db_name?retryWrites=true&w=majority

The Sharded/Legacy Format

If you see a long string with shard-00-00 and port 27017, you are looking at the legacy connection string. Atlas sometimes provides this for older drivers.

Skeptical Check: If your app supports it, always use the SRV format. It’s easier to manage and handles DNS seeds automatically.

4. Integration: Connecting the Pipes

For Standard Node.js Apps

If you are running a standalone script to ingest Nostr data, you’ll need the driver:

npm install mongodb

For Meteor.js

Meteor doesn’t need a separate driver install for the core database; it just needs an environment variable. When you run your app locally but want to use the cloud database, use the MONGO_URL prefix:

The Local Run Command:

MONGO_URL="mongodb+srv://kheai_db_user:YOUR_PASSWORD@cluster0.xnv0qyc.mongodb.net/db_name" meteor run

The Production Deployment (mup):

If you are using meteor-up (mup), your settings.json or mup.js will look like this:

env: {
  MONGO_URL: "mongodb+srv://kheai_db_user:XXXXXX@cluster0.mongodb.net/db_name?retryWrites=true&w=majority",
  // Optional: If you use a separate DB for your Oplog (scaling)
  MONGO_OPLOG_URL: "mongodb://..." 
}

5. Summary Table for Quick Reference

ComponentSettingNotes
Database Namedb_nameRename this to kheai_prod or kheai_dev.
Collectiondb_colThink of this as a “Table” (e.g., intelligence_logs).
Port27017Standard Mongo port (Hidden in SRV strings).
Auth SourceadminUsually required in legacy strings to verify the user.

Pro-Tips for the Sovereign Developer

  1. The .env Rule: Never, ever hardcode your connection string in your main app file. Use a .env file and add it to your .gitignore.
  2. Naming Matters: Don’t just stay with Cluster0 and db_name. As you scale, having a database named kheai_main and collections like nostr_events and ai_responses will save your sanity.
  3. Local Fallback: If you’re traveling or have bad internet, install MongoDB locally via Docker or Homebrew. You can swap your MONGO_URL to mongodb://127.0.0.1:27017/kheai and work offline.

Share this post on:

Next Post
From Export to .env File (Meteor Security Dev)