Sobes.tech
Junior — Middle

Do you have experience working with the MongoDB database?

sobes.tech AI

Answer from AI

Yes, experience with MongoDB includes:

  • Creating and managing collections and documents in BSON format.
  • Using MongoDB drivers for Node.js (e.g., mongodb or mongoose).
  • Performing CRUD operations (create, read, update, delete).
  • Indexing for query optimization.

Example of simple connection and query using the mongodb driver:

const { MongoClient } = require('mongodb');

async function run() {
  const client = new MongoClient('mongodb://localhost:27017');
  try {
    await client.connect();
    const db = client.db('testdb');
    const collection = db.collection('users');

    // Insert a document
    await collection.insertOne({ name: 'Ivan', age: 30 });

    // Find a document
    const user = await collection.findOne({ name: 'Ivan' });
    console.log(user);
  } finally {
    await client.close();
  }
}

run().catch(console.dir);