Archive for August, 2016

MongoDB: reduce file size

August 23, 2016 Leave a comment

I have a small Digital Ocean VPS with MongoDB with 20 GB storage. The database dump is 1.7 GB, but the directory /var/lib/mongodb occupies about 7 GB disk space. If it goes on like that, I will run out of free space.

MongoDB 3 uses the WiredTiger storage engine, but before that the mmapv1 engine was the default. The mmapv1 has two options to reduce file size but WiredTiger doesn’t support these options :(

So I switched back to mmapv1. Here is my /etc/mongod.conf file that enables file size reduction:

# mongod.conf

# for documentation of all options, see:

# Where and how to store data.
  dbPath: /var/lib/mongodb
    enabled: true
  engine: mmapv1
    preallocDataFiles: false
    smallFiles: true
#  wiredTiger:

# where to write logging data.
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
  port: 27017

Notice preallocDataFiles and smallFiles. Keep in mind that they may have negative impact on the performance. In my case I was just collecting a lot of data and not running out of free space was more important.

My new /var/lib/mongodb is 4 GB now, not 7 GB.

To figure out if Mongo uses WiredTiger or mmapv1, execute this in the mongo shell:

> db.serverStatus().storageEngine

MongoDB: connect remotely

August 8, 2016 Leave a comment

I have a Digital Ocean VPS running MongoDB. There is a web application on this machine that is on port 80. MongoDB is hidden from the outside world and can only be accessed internally. There is also an SSH port where I can log in.

How to connect to my MongoDB server from home? Say I want to use a graphical client, e.g. MongoChef. The client runs on my home machine and I want to connect to MongoDB with it on my DO VPS. How to do that?

I found the solution here. In short: we connect securely to our database through an SSH tunnel.

Make sure that:

  • you can SSH into your Mongo droplet
  • your MongoDB is bound to localhost

For connecting, I use this script:

cmd="ssh -p ${REMOTE_SSH_PORT} -L ${LOCAL_PORT}:localhost:${REMOTE_MONGO_PORT} user@your.remote.ip"
echo "#" $cmd
echo "# connect on your home machine to port ${LOCAL_PORT}"
echo "# example:    mongo --port ${LOCAL_PORT}"

The default SSH port is 22, but it’s a good idea to change it. With the command “ssh -p ${REMOTE_SSH_PORT} user@your.remote.ip” I could log in to my VPS. However, MongoDB was not accessible from outside, thus executing “mongo --host your.remote.ip --port ${REMOTE_MONGO_PORT}” failed.

The SSH tunneling above works as follows. On your home machine you open the port ${LOCAL_PORT} that is connected to your remote machine via the SSH port ${REMOTE_SSH_PORT}, and the connection is tunneled to localhost:${REMOTE_MONGO_PORT}, where localhost means the remote machine where we logged in with SSH.

So, when you execute the script above, you’ll have to log in to your remote machine via SSH. Then open a new terminal and type “mongo --port 2345” and voilá, you are connected to MongoDB on your remote machine!

If you use a Mongo client (e.g. MongoChef), then simply create a new connection and specify localhost with port 2345. Connect, and you are in.

It works as long as you are logged in in a terminal via SSH. When you log out, the local port closes that is tunneled to your remote machine.

Bitbucket: create SSH key, upload SSH key

August 4, 2016 Leave a comment

GitHub is very good for open source projects, I also use it. However, if you want to work on a private project alone or with some of your friends and you don’t want to share the code, then Bitbucket could be a better choice since it allows you to create unlimited number of private repositories.

You are at a new machine of yours. You create a new repository, clone it on your localhost, make some changes, and when you try to push the changes to the repo, you get an error message that you should upload your SSH key. How to do that?

Check if you have an SSH key:

$ cat ~/.ssh/

If you don’t have an SSH key, create one:

ssh-keygen -t rsa -b 4096 -C ""

Accept the default file location and provide a passphrase.

Then copy the content of “~/.ssh/” to the clipboard and add it to your account by following these steps.

Categories: Uncategorized Tags: ,

how to configure a Digital Ocean Ubuntu 16.04 box

August 4, 2016 Leave a comment

I’ve updated my Digital Ocean Notes on GitHub. Now it includes information about configuring an Ubuntu 16.04 box.

Categories: ubuntu Tags: , ,

systemd notes

August 3, 2016 Leave a comment
Categories: ubuntu Tags: ,

[manjaro] fix for KDE apps after an update

August 2, 2016 Leave a comment

After updating Manjaro, my KDE apps looked strange. It was some theme problem. The fix is here:

Categories: manjaro