Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generates empty folders #42

Open
p0ria opened this issue Aug 13, 2020 · 2 comments
Open

Generates empty folders #42

p0ria opened this issue Aug 13, 2020 · 2 comments

Comments

@p0ria
Copy link

p0ria commented Aug 13, 2020

I use this library inside my nest.js service.
Collection folders get created but they are all empty.
This is my code:

`var backup = require('mongodb-backup');
import { Injectable, Logger } from "@nestjs/common";

@Injectable()
export class BackupDbService {
private readonly logger = new Logger(BackupDbService.name);
mongoUrl = 'mongodb://localhost:27017/admin';

backupDb() {
    try {
        backup({
            uri: this.mongoUrl, // mongodb://<dbuser>:<dbpassword>@<dbdomain>.mongolab.com:<dbport>/<dbdatabase>
            collections: ['rates'],
            root: 'db',
            callback: function(err) {
                if (err) {
                  console.error(err);
                } else {
                  console.log('finish');
                }
              }
          });
    } catch (err) {
        this.logger.error(err);
    }
}

} `

@lihaibh
Copy link

lihaibh commented Sep 7, 2020

@p0ria
I think i know what is the problem it one of the bugs of this library.
In my organisation we had a collection that contains documents with sensitive property keys such as:
person.fullname
Mongodb cant handle insertion of documents with properties that contains the dot character.
Unfortunately even if 1 document has an issue the insertion of the whole collection fails and you wont receive any error.

Ive created my own version of MongoDB backup and restore library you can take a look at my solution:
https://github.com/lihaibh/mongodb-snapshot/blob/83b12d377a1ec387f0bcf121b294cdd45504ac76/src/connectors/MongoDBDuplexConnector.ts#L258

BTW it doesn't create any "side effect" files like a directory for creating the backup.
you can try using it and i will help you.

@OlivierChirouze
Copy link

See #27 (comment) for a final solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants