TylerBrock / mongo-hacker

MongoDB Shell Enhancements for Hackers
tylerbrock.github.io/mongo-hacker
MIT License
1.79k stars 235 forks source link

New API method: db.getMongo().getDatabaseNames() #133

Closed pvdb closed 9 years ago

pvdb commented 9 years ago

Hey @TylerBrock,

This PR adds a new API method to the MongoDB shell: db.getMongo().getDatabaseNames() which returns a list of database names, similar to how db.getCollectionNames() returns a list of collection names.

The rationale for introducing this new API method is that it allows for advanced cross-database scripting within a single MongoDB shell session... I plan to use it as the basis for a new count collections helper which will print out a list of database names followed by the number of collections in each of them.

Based on this new API method, I was then also able to refactor/simplify the implementation of the show dbs helper, which makes up the remaining commits in this PR (which I've kept very small again, similar to what I did in #129, which should make reviewing the PR a bit easier).

Thanks, @pvdb!

get_database_names

pvdb commented 9 years ago

@TylerBrock - FYI: sample output of the forthcoming count collections helper, which will be implemented on top of this new getDatabaseNames() API method...

count_collections_helper

/cc @stennie

TylerBrock commented 9 years ago

Hi @pvdb sorry I haven't had a chance to take a look at this yet. Recovering from being sick. I will do so soon.

pvdb commented 9 years ago

Hi @pvdb sorry I haven't had a chance to take a look at this yet. Recovering from being sick. I will do so soon.

No worries, @TylerBrock ... hope you're feeling better! Keep up the good work with mongo-hacker... I'm advocating it like a mad man at work, and people are really excited about it!

pvdb commented 9 years ago

Hey @TylerBrock, I've got some other pull requests queued up behind this one, so it'd be great if you'd be able to have a look at this one... thanks!

TylerBrock commented 9 years ago

Hi, apologies for the delay @pvdb. I will look first thing tomorrow.

TylerBrock commented 9 years ago

@pvdb got a chance to go through it just now. Looks great, thank you for all the hard work!

Sorry again for the delay. I'm feeling much better now, thank you for the well wishes! I'll be much more responsive in the future, just had a horrible stomach bug that knocked me out and I've been behind on work. I hope you understand.

TylerBrock commented 9 years ago

Also, FYI I just tagged and published v0.0.8 to npm but in the future try not to bump the version number in a pull request for a feature. Thanks again.

pvdb commented 9 years ago

Cheers, @TylerBrock, good to hear you're feeling better, and that you like the changes! Understood about the version number... will keep that in mind for future pull requests!