Cloudflare MongoDB
MongoDB Driver for Cloudflare Workers
Example
import { CloudflareMongoClient, Document } from 'cloudflare-mongodb'
type User = Document & {
firstName: string
}
const client = new CloudflareMongoClient({
/**
* Proxy api url
*/
apiServiceUrls: ['https://mongodb-proxy.g7p.io'],
/**
* Authentication token, keep it secured
*/
apiAuthToken: process.env.API_AUTH_TOKEN,
})
const db = client.db('g7')
const users = db.collection<User>('users')
// Insert
const user = await users.insertOne({
firstName: 'Ezeki',
})
// Update
await users.updateOne(
{ _id: user?.id },
{
$set: {
firstName: 'EzekiX',
},
},
)