boly38/node-mongotools

includeCollections saves only the last collection

Closed this issue · 6 comments

Hello, im trying to save the three collections as in the example, but aways saves only the last array item, im doing somethiong wrong ?

const options = new MTOptions({
   uri: DATABASE_URL,
   path: pathToBackup,
   db: process.env.DATABASE,
   includeCollections: [
      `plataformas`,
      `ideias`,
      `userorganizationprofiles`,
   ],
   port: process.env.MONGO_PORT,
   });

Hi @CristianoStav thanks for this report 👍

linked to #38

I looked at dump options quickly, and seems that include cant be repeated like exclude.
I'll suggest a fix asap

mongodump options

According to the documentation https://docs.mongodb.com/database-tools/mongodump/ there is no explicit options for that. However, if you do not specify a collection, then all collections of the given database are dumped. You may exclude many collections by specifying the option –excludeCollection multiple times. (...)
There’s an open feature request to add similar options for including collections that you can watch or upvote: TOOLS-1731 26.

mongo doc

--collection=, -c=
Specifies a collection to backup. If you do not specify a collection, this option copies all collections in the specified database or instance to the dump files.

--excludeCollection=
Excludes the specified collection from the mongodump output. To exclude multiple collections, specify the --excludeCollection multiple times.

--excludeCollectionsWithPrefix=
Excludes all collections with a specified prefix from the mongodump outputs. To specify multiple prefixes, specify the --excludeCollectionsWithPrefix multiple times.

So the fix PR I will suggest would be:

  • a) mark includeCollections option as deprecated (code+doc)
  • b) includeCollections option (array value) will continue to work like now and undertake the last string of the array only.
  • c) Using includeCollections option will produce warn log to inform about deprecated state.
  • d) add collection option (to map mongodump binary option) : this option accept one string or an array with one string But an array with 2 or more entries will produce an error.

@CristianoStav and @antonio-goncalves ; what do you think about this suggest ? feel free to give your opinion right here.

@boly38 and @CristianoStav Sorry for my late response.

When I suggested to include the option "includeCollection" and "excludeCollections" I didn't realized that was not possible to include several "--collection" options, so the bug described here is my bad.

@boly38 I agree with your suggestion

I didn't realized that was not possible to include several "--collection" options, so the bug bug described here is my bad.

no worry this is a good feature to have, I was really happy to include your PR, mistakes are part of software development, we go ahead and that's nice !

fixed in 1.3.0