Node.js is a popular runtime platform to create programs that run on it.

It lets us run JavaScript outside the browser.

In this article, we’ll look at how to start using Node.js to create programs.

Creating Indexes

We can create indexes in our collection to let us enable searches in the collection.

For example, we can write:

const { MongoClient } = require('mongodb');
const connection = "mongodb://localhost:27017";
const client = new MongoClient(connection);

async function run() {
  try {
    await client.connect();
    const db = client.db("test");
    const testCollection = await db.collection('test');
    const indexResult = await testCollection.createIndex({ name: 1 });

#technology #javascript #programming #node.js #node

Node.js Basics — MongoDB Indexes
1.35 GEEK