Monday, November 23, 2015

RoboMongo - A great MongoDB GUI for Mac OS X

I have been looking for a good enough MongoDB GUI to replace RockMongo which is one of the best web based GUI I have used for many years.

MongoDB is a great No SQL database, but surprisingly I have not seen any good quality GUI for Mac OS X, the last project that came close to becoming a replacement for RockMongo was Mongo Hub.  Mongo Hub had limited functionality and the project seems to have gotten stuck (in-active).

Today, I want to introduce RoboMongo.  It has minimal GUI, but it is easy to use.



You simply just need to create connection profiles and RoboMongo supports SSH tunneling which makes it easy to use and saves time.

RoboMongo's concept is simple, it is a command / script base GUI concept, the called it shell-centric, which means you need to know some basic MongoDB javascript like commands to be able to query and perform database actions.

I have been using RoboMongo since only about 2 weeks ago.  Since then I have rarely return back to use RockMongo.

Try RoboMongo, leave a comment of how you like it or tell me if you have found something better.

Thanks

-Hadi


Saturday, August 1, 2015

Rename Database using Copy then delete method in MongoDB

Simplest way to rename a MongoDB database using MongoDB CLI:

db.copyDatabase('old_name', 'new_name');
use old_name
db.dropDatabase();

Fastest way to install MongoDB PHP Extension / Driver

By far the fastest and easiest way to install MongoDB PHP Extension (upgradable) via command line.

pecl install mongo 

yep, that is it!

In the future you can upgrade it to newer versions using:

pecl upgrade mongo

Please make sure to use only STABLE version.

Simple MongoDB database restore command line script

MONGODB RESTORE Database / Collection

ENTIRE DATABASE or a particular COLLECTION

Command below will restore entire database from directory mongodb-db_name-YYYYMMDD

mongorestore --host 127.0.0.1 --port 27017 /your_backup_dir/mongodb-20140213




Simple MongoDB BackUp command line script

MONGODB BACKUP EXAMPLE

Backing Up Entire Database:

Command below will backup entire database + create a directory mongodb-db_name-YYYYMMDD

mongodump --host 127.0.0.1:27017 -d db_name --out /your_backup_dir/mongodb-db_name-YYYYMMDD >> /dev/null

Backing Up Collection inside a Database:

Command below will backup a collection inside a particular database + create a directory mongodb-collection_name-YYYYMMDD

mongodump --host 127.0.0.1:27017 -d db_name -c collection_name --out /your_backup_dir/mongodb-db_name-collection_name-YYYYMMDD  >> /dev/null



[SOLVED] MongoDB error: The MongoCursor object has not been correctly initialized by its constructor (PHP Driver)

I have been plagued by this error message intermittently for about 6-months.

PHP Fatal error:  Uncaught exception 'MongoException' with message 'The MongoCursor object has not been correctly initialized by its constructor' in /data_local/app/dff/inc/DffDataObj_db_mongo.class.php:37

Specifically "The MongoCursor object has not been correctly initialized by its constructor"

 I have searched on Google off and on but never found any good solution.

Finally I accidentally found the solution, because I installed another web server which has a newer MongoDB PHP Extension Driver.

Instantly the problem is gone.

It turns out culprit was the PHP Extension version that had the problem was 1.5.0, I got that from PECL. The error usually happen when a MongoDB connection has been opened for at least 0.5 second and that connection was either used in loop doing multiple queries to Mongo, or it was used to query multiple collections. In any case, the error was somewhat intermittent and hard to debug.

The solution and how-to fix this problem is very simple, you simply need to upgrade it.

Type this on your shell:

pecl list

That should tell you all PHP packages you have installed using PECL.

Mine looks like this:

Installed packages, channel pecl.php.net:
=========================================
Package Version State
mongo   1.6.10  stable

But before I upgraded that used to say 1.5.0

Anyways here is the command I used to upgrade to latest stable version:

pecl upgrade mongo

After upgrade process completed, you can run

pecl list 

again to double check to make sure your version has been upgraded.

and you can also make sure on PHP info using the following command:

php -i

(look for mongo section and check the version there)

That is all... I hope that help some one like me! :-)

Thursday, July 30, 2015

How to Rotate Log in MongoDB (5 min setup)

This is what I use to rotate my MongoDB log

Assumptions:  You have installed MongoDB and you can execute 'mongo' shell command-line utility from anywhere in your shell.


  1. Create Javascript File:

    nano /home/myname/mongodb_rotate_log.js

    Add the following line:

    db.runCommand( { logRotate : 1 } );

    press CTRL-X, Y, Enter    (to save and exit)

  2. Add to mongo shell command CRONTAB
    crontab -e

    Add the following line:

    33 3 * * 6 mongo admin /home/myname/mongodb_rotate_log.js

    that line will schedule log rotation every Saturday night at 3:33am.

    press CTRL-X, Y, Enter    (to save and exit)

  3. Add shell command to clean-up after ## days

    crontab -e

    Add the following line:

    19 4 * * * find /log/ -type f -mtime +30 | xargs rm

    the line above will schedule log cleanup at /log/ directory recursively
    it will remove any file older than 30 days

    press CTRL-X, Y, Enter    (to save and exit)