Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
# 1. Create a free cluster at https://cloud.mongodb.com # 2. Add your IP to the Network Access allowlist # (or use 0.0.0.0/0 for dev — never in production) # 3. Create a database user with a strong password # 4. Copy your connection string — looks like: # mongodb+srv://<user>:<password>@cluster0.abc12.mongodb.net/myDB # 5. Install the driver npm install mongodb # 6. Connect from Node.js const { MongoClient, ServerApiVersion } = require('mongodb') const uri = process.env.MONGODB_URI const client = new MongoClient(uri, { serverApi: { version: ServerApiVersion.v1, strict: true, deprecationErrors: true } }) async function run() { await client.connect() await client.db("admin").command({ ping: 1 }) console.log("Connected to Atlas!") await client.close() } run().catch(console.error)
Result
Open