Skip to content

Archive

MongoDB

2 articles
Database Updated 07 Sep 2025 2 min read

Exporting and Restoring MongoDB Databases with `mongodump` and `mongorestore`

Backups are an important part of MongoDB administration. Two standard command-line tools for logical backups and restores are mongodump and mongorestore, which work with BSON data and collection metadata. 1. Back Up a Database with mongodump Use mongodump to create a BSON backup that can later be restored. Basic syntax: mongodump -d <database_name> -o <backup_directory> -d <database_name> → the database to back up. -o <backup_directory> → the directory where the dump will be written. Example:

Database Updated 07 Sep 2025 2 min read

Using MongoDB Aggregation to Build Hierarchical Category Structures

Applications often need to represent hierarchical data such as parent categories, child categories, and deeper descendants. MongoDB’s aggregation framework includes $graphLookup, which can recursively traverse relationships within a collection. This article shows how to use $graphLookup to retrieve a category hierarchy from documents that reference their parent category. 1. Data Structure Consider the following documents in a MongoDB collection: { "_id" : 1, "cat_id" : 1, "title" : "Parent Category", "parent" : null } { "_id" : 2, "cat_id" : 2, "title" : "Child Category", "parent" : 1 } { "_id" : 3, "cat_id" : 3, "title" : "Sub Child Category", "parent" : 2 } The relationships are: