mongodump/readme.md

92 lines
4.2 KiB
Markdown
Raw Permalink Normal View History

2024-04-14 15:15:00 +00:00
# @push.rocks/mongodump
a tool to handle dumps of MongoDB databases
## Install
To use @push.rocks/mongodump in your project, run:
```bash
npm install @push.rocks/mongodump --save
```
2022-06-05 19:04:16 +00:00
## Usage
2024-04-14 15:15:00 +00:00
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:
```typescript
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:
```typescript
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:
```typescript
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:
```typescript
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.
## License and Legal Information
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](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
2022-06-05 19:04:16 +00:00
2024-04-14 15:15:00 +00:00
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.
2022-06-05 19:04:16 +00:00
2024-04-14 15:15:00 +00:00
### Company Information
2022-06-05 19:04:16 +00:00
2024-04-14 15:15:00 +00:00
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
2022-06-05 19:04:16 +00:00
2024-04-14 15:15:00 +00:00
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
2022-06-05 19:04:16 +00:00
2024-04-14 15:15:00 +00:00
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.