Skip to content

Instantly share code, notes, and snippets.

Last active July 14, 2021 21:16
What would you like to do?
MongoDB Quickstart

MongoDB Quickstart


  1. Read:
  2. Read:


  1. $ brew tap mongodb/brew
  2. $ brew install mongodb-community - Installs mongodb server on your machine.1
  3. $ brew services start mongodb-community - Starts mongodb server locally.2
  4. $ npm install mongodb - Installs mongodb node package.



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

const URI = "mongodb://localhost:27017/";

const insertStuff = async () => {
  const client = await new MongoClient(URI).connect();
  const db = client.db("fec");
  const collection = db.collection("items");
  await collection.insertOne({ name: "stuff" });
  // You have to close the connection, or the app will hang.
  // You'll probably want to do this in an afterAll hook in your tests.
  await client.close();



  1. Bulk writes:
  2. API Docs:
  3. Shell Docs:

1Linux instructions here.

2By default, this will run on localhost:27017.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment