MongoClient

noun

say it: “MAHNG-goh KLY-ent” /ˈmɑŋɡoʊ ˈklaɪənt/

The object in MongoDB's Node.js driver that connects a program to a database server and gives it access to collections.

What is a MongoClient?

A MongoClient is the official Node.js driver's connection to a MongoDB server. You make it from a connection string, pick a database and a collection with db() and collection(), and close() hangs up.

import { MongoClient } from "mongodb";

const client = new MongoClient("mongodb://127.0.0.1:27017");
const plants = client.db("plant_shop").collection("plants");
await plants.insertOne({ name: "Snake Plant", price: 24.99 });
await client.close();

In a sentence

  • “The plant shop's server makes one MongoClient when it starts and shares it with every route.”
  • “Call close() on the MongoClient at the end of a script, or Node keeps running.”

Level: Apprentice · More MongoDB terms at this level

Updated