Mongodb Compass UI tutorials and examples

This tutorial explains Mongo Compass UI tutorials with examples

Mongodb Compass is a UI for Visually managing MongoDB documents and collections

Compass comes with a Mongodb Installation pack. You can also install it separately

What is MongoDB Compass UI

MongoDB Compass UI is a Client to manage collections, databases, and documents.

Features

  • Manage Connections to connect to multiple MongoDB databases
  • List Create, and Modify a Database and Collection
  • Performance Metrics such as Read, Write, Network and Memory monitor
  • Query MongoDB database collection using queries and aggregations pipeline
  • Construct pipeline stages in Aggregations
  • View indexes and Schema validation
  • In-built Mongo Shell support to run command line javascript queries
  • Export Collection to JSON and CSV
  • Import JSOn and CSB into collection

How to Connect to Server in Mongo Compass UI

Open Mongo Compass UI

  • Create a New Connection Button on it
  • Connection window, enter URI details

URI is a connection string for the MongoDB server. URI: mongodb://localhost:27017 mongodb is a protocal localhost is the server hostname 27017 is a Server port

You can change all these details

Mongodb Compass Connection create
  • Next, Click on the Save & Connect button
  • It asks string name to save this as a connection
  • local-connection name given Popup
  • It connected to the MongoDB Server, Shown in the below screen
Mongodb Compass UI query database
  • It shows all the database of a Server
  • Also, There is an Icon bottom right to open Mongo Queries

How to Query Documents by ObjectId in MongoDB Compass UI

In MongoDB Compass, You can do it in Multiple ways

The first way is using the Query UI pane.

  • Open MongoDB Compass and connect to Server

  • Open collection

  • in the Filter Search Query, Add the below check

    {_id:ObjectId('5a9427648b0beebeb69579cc')}
    
  • Click on the Find button, and display the result in the Result Window.

Mongodb Compass UI query collection by ObjectId

Second way,

  • Open the MONGOSH shell in Compass, MONGOSH is located in the bottom right icon
Mongodb Compass UI query database
  • Next Run the below commands to select the database
>>>use moviesdb;
switched to db moviesdb
>>>show collections;
comments
movies
sessions
theaters
users
  • Next run the below command

db.users.find() search collection with given filter. Filter is an objectid.

>>>db.users.find({'_id': ObjectId('59b99db4cfa9a34dcd7885b6')});
{
  _id: ObjectId("59b99db4cfa9a34dcd7885b6"),
  name: 'Ned Stark',
  email: '[email protected]',
  password: '$2b$12$UREFwsRUoyF0CRqGNK0LzO0HM/jLhgUCNNIJ9RJAqMUQ74crlJ1Vu'
}