Develop a Node.js script that connects to a MongoDB database, creates a "users" collection, and inserts 10 sample user documents with random names and ages.
PLAINFORMAT
const MongoClient = require('mongodb').MongoClient;
const faker = require('faker');

const uri = 'mongodb://localhost:27017';
const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true });

client.connect(async (err) => {
  if (err) {
    console.error('Error connecting to MongoDB:', err);
    return;
  }

  const db = client.db('test');
  const usersCollection = db.collection('users');

  const users = Array.from({ length: 10 }, () => ({
    name: faker.name.findName(),
    age: Math.floor(Math.random() * 100),
  }));

  try {
    const result = await usersCollection.insertMany(users);
    console.log(`Successfully inserted ${result.insertedCount} users`);
  } catch (error) {
    console.error('Error inserting users:', error);
  } finally {
    client.close();
  }
});