A tool to create and manage dumps of MongoDB databases, supporting data export and import.
Go to file
2024-05-29 14:11:21 +02:00
.vscode fix(core): update 2022-06-05 21:04:16 +02:00
test fix(core): update 2022-06-06 16:01:25 +02:00
ts fix(core): update 2022-06-06 16:52:41 +02:00
.gitignore fix(core): update 2022-06-05 21:04:16 +02:00
.gitlab-ci.yml fix(core): update 2022-06-05 21:04:16 +02:00
license fix(core): update 2022-06-05 21:04:16 +02:00
npmextra.json update tsconfig 2024-04-14 17:15:00 +02:00
package-lock.json 1.0.8 2022-06-06 16:52:42 +02:00
package.json update description 2024-05-29 14:11:21 +02:00
pnpm-lock.yaml switch to new org scheme 2023-07-11 00:03:01 +02:00
readme.hints.md update tsconfig 2024-04-14 17:15:00 +02:00
readme.md update tsconfig 2024-04-14 17:15:00 +02:00
tsconfig.json update npmextra.json: githost 2024-04-01 21:33:23 +02:00

@push.rocks/mongodump

a tool to handle dumps of MongoDB databases

Install

To use @push.rocks/mongodump in your project, run:

npm install @push.rocks/mongodump --save

Usage

This guide provides an overview of how to work with @push.rocks/mongodump to handle dumps of MongoDB databases efficiently.

Setting up a MongoDB Dump Target

First, you'll need to describe your MongoDB database using an interface provided by the module. Here's a sample descriptor:

import { IMongoDescriptor } from '@tsclass/tsclass';
import { MongoDump, MongoDumpTarget } from '@push.rocks/mongodump';

const myMongoDescriptor: IMongoDescriptor = {
  mongoDbName: '<database_name>',
  mongoDbUser: '<database_user>',
  mongoDbPass: '<database_password>',
  mongoDbUrl: 'mongodb+srv://<user>:<password>@<cluster_url>/<dbname>?retryWrites=true&w=majority',
};

Creating and Using the MongoDump Instance

To interact with MongoDB for dumping purposes, you'll use the MongoDump class:

async function setupMongoDump() {
  const mongoDump = new MongoDump();
  const mongoDumpTarget = await mongoDump.addMongoTargetByMongoDescriptor(myMongoDescriptor);

  // mongoDumpTarget can now be used for further operations
}
setupMongoDump();

Dumping Collections to a Directory

To dump the collections of a database into a directory with files representing each document, you can use the dumpCollectionToDir method. This method is useful for creating backups or migrating data:

async function dumpCollections() {
  const mongoDump = new MongoDump();
  const mongoDumpTarget = await mongoDump.addMongoTargetByMongoDescriptor(myMongoDescriptor);

  await mongoDumpTarget.dumpAllCollectionsToDir('./path/to/dumpDir', null, true);
  // This dumps all collections to the specified directory, cleaning the directory before dumping.
}
dumpCollections();

Advanced Dumping Options

For more control over the dumping process, including naming conventions for dumped files or handling specific collections, you can explore methods like dumpCollectionToDir for individual collections and advanced configurations concerning directory cleanliness and document naming.

Shutting Down Properly

It's important to close down database connections properly once your dumping operations are complete:

async function shutDownMongoDump() {
  const mongoDump = new MongoDump();
  await mongoDump.stop();
  // Closes all open database connections gracefully
}
shutDownMongoDump();

Conclusion

The @push.rocks/mongodump module provides a flexible approach to handling MongoDB database dumps, whether it's for backup, migration, or other purposes. By leveraging TypeScript and modern async patterns, it integrates smoothly into modern Node.js applications focused on MongoDB interactions.

This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the license file within this repository.

Please note: The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.

Trademarks

This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.

Company Information

Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany

For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.

By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.