Skip to content

Latest commit

 

History

History
36 lines (28 loc) · 922 Bytes

File metadata and controls

36 lines (28 loc) · 922 Bytes

MongoDB

This section covers MongoDB.

Topics Covered

  • Introduction to MongoDB
  • CRUD operations
  • Indexing and aggregation
  • Data modeling

Resources

Code Examples

const { MongoClient } = require('mongodb');
const uri = "your_mongodb_uri";

const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

async function run() {
    try {
        await client.connect();
        const database = client.db('sample_db');
        const collection = database.collection('sample_collection');
        
        const doc = { name: "John", age: 30, city: "New York" };
        const result = await collection.insertOne(doc);
        console.log(`New document inserted with _id: ${result.insertedId}`);
    } finally {
        await client.close();
    }
}
run().catch(console.dir);