npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongo-bongo

v1.2.1

Published

A tool for easy MongoDB database configuration and backup

Downloads

9

Readme

Mongo Bongo

An opinionated tool for managing MongoDB databases. It allows you to easily:

  • Configure authenticated databases users
  • Manage user passwords
  • Perform backups and restores
  • Rename databases
  • Work with replica sets

Note, this tool has been tested to work with [MongoDB 4.x(https://docs.mongodb.com/manual/), macOS with Homebrew, and Ubuntu 18.04.

Users

In an authenticated database, users are stored in the admin database. As far as this tool is concerned, there are two categories of users:

  • Administrative Users: root, backup and restore.
  • Database Users: admin and user.

root user is only used to manage users across databases. backup and restore are used for backing up and restoring databases respectively.

Within a database admin users are used for things like re-indexing. The user is for everything else, and is the user that the an API process will connect as.

admin Database

To create an admin database and add the root, etc.. users you must first bind Mongo to localhost only and then disable security:

bongo mongo --no-auth --no-bind-all

Now add the admin database users:

bongo users admin

Running the command when the users already exists just confirms their existence. You can change passwords in future by running:

bongo users admin --new-passwords

Now re-enable security (and optionally bind to all IP addresses):

bongo mongo --auth --bind-all

Credentials File

After running bongo users admin you will have a ~/.bongo/credentials.json5 file that contains the users passwords. Having this file makes it easy to find the appropriate passwords to add to your MongoDB URI's when configuring your API services.

NOTE: If this is alarming to you, realize that it is no different from that way the systems like AWS work when they store login credentials in ~/.aws/credentials files. The file has the mode set to allow only the user that creates it to read and modify it. Just make sure that the security for account is good, by using only SSH authentication for example.

Other Databases

To create the approriate users for other databases, with security enabled:

bongo users <db>

And to regenerate passwords run:

bongo users <db> --new-passwords

Backups

To backup a database run:

bongo backup <db>

You'll get a timestamped .tar.gz file in the current directory. Specify --output <dir> to change the output directory. This file only contains non-system collections and is moded to only be accessible to the current user. It's a standard, compressed tar file. You can specify --output to give a different directory for where the file will be placed, but the name will always include the database name and the date/time.

Specify --port to use a non-default mongod instance. Specify --new-name to rename the database when backing it up. This is about as easy and fast as a database rename operation gets in MongoDB.

Restorations

To restore a backup:

bongo restore <archive>

Restores the database, dropping any existing collections with the same. You can set the admin and user users with bongo as above if needed, or just copy over the credentials.json file manually.

You can specify --port for non-default mongod instances, e.g. replica sets.

Other

The tool generates cryptographically strong 16 character alphanumeric passwords that should not give any problems when used on the command line or in MongoDB URI's with passwords, e.g. mongodb://user:zY99Ab8cddf8e01x@localhost:27107/db-name.

The bongo mongo command reads the mongod.conf file as YAML and rewrites it stripping any comments If comments in the .conf file are important to you then please submit a pull request to add that functionality.