Skip to content

Migration Guide

Magnus supports MongoDB filter syntax ($eq, $in, $gt, etc.) via the /mql/* routes. Simple queries run on D1 JSON1 — complex aggregation stages ($lookup, $facet, $graphLookup) automatically route to a MongoDB right-behind when configured.

Replace your MongoDB connection with Magnus API calls:

// Before (MongoDB driver)
const docs = await db.collection('articles').find({ status: 'published' }).toArray();
// After (Magnus)
const res = await fetch('https://magnusdb.dev/api/mql/find', {
method: 'POST',
headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ collection: 'articles', filter: { status: 'published' } }),
});

Magnus accepts Postgres-dialect SQL directly. Queries with Postgres-specific syntax automatically route to Hyperdrive.

// Before (pg driver)
const { rows } = await pool.query('SELECT * FROM users WHERE email ILIKE $1', ['%@acme.com']);
// After (Magnus)
const res = await fetch('https://magnusdb.dev/api/sql/query', {
method: 'POST',
headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ sql: 'SELECT * FROM users WHERE email ILIKE ?', params: ['%@acme.com'] }),
});

Magnus KV commands are Redis-compatible. Simple get/set/delete use Cloudflare KV; advanced commands route to Upstash Redis.

// Before (ioredis)
await redis.set('session:abc', 'active', 'EX', 3600);
// After (Magnus)
await fetch('https://magnusdb.dev/api/kv/session:abc', {
method: 'PUT',
headers: { Authorization: `Bearer ${API_KEY}`, 'Content-Type': 'application/json' },
body: JSON.stringify({ value: 'active', ttl: 3600 }),
});