Category Archives: MongoDB

“WARNING: soft rlimits too low” in MongoDB with Mac OS X

If you get this warning when you connect to mongo shell in Mac OX X:

** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

You can increase that limit by just running this on the Mac OS X shell:

launchctl limit maxfiles 1024 1024

This other command has the same effect but it will only last until the next system reboot:

ulimit -n 1024

Restart mongod and it shouldn’t complain any more.

Solve “mongodb cannot be built while v8 is active” in MacPorts

While updating all the ports of macports I got this error:

--->  Configuring mongodb
Error: mongodb cannot be built while v8 is active.
Error: Please deactivate v8 and try again.
Error: You can reactivate v8 again later.
Error: org.macports.configure for port mongodb returned: v8 is active

To deactivate v8 run:

sudo port -f deactivate v8

Run the update process again:

sudo port upgrade outdated

And finally activate v8 again:

sudo port activate v8

Ref: http://widgetbook.blogspot.com.es/2013/08/mongodb-and-macports-and-v8.html

“AttributeError: ‘module’ object has no attribute ‘MongoClient’” error with Pymongo in Ubuntu 12.04

"Error AttributeError: 'module' object has no attribute 'MongoClient'" con Pymongo en Ubuntu 12.04">

I’m currently doing the M101P: MongoDB for Developers online course.

course_image

I had this error while running one of the homeworks with pymongo in Ubuntu 12.04:

AttributeError: 'module' object has no attribute 'MongoClient'

I had previously installed pymongo with apt-get like this:

sudo apt-get install python-pymongo

It looks like the package is outdated or broken so I had to remove the pymongo I had installed before and reinstall it using PiP:

sudo apt-get purge python-pymongo
sudo apt-get install python-pip
sudo pip install pymongo

Ref: http://stackoverflow.com/questions/17624416/cant-import-mongoclient

MongoDB: Recover Data after an Unexpected Shutdown in Ubuntu

If you try to run mongod but it fails to start and have this error in the log file (/var/log/mongodb/mongodb.log) you’ll have to repair your db.

************** 
Unclean shutdown detected.
Please visit http://dochub.mongodb.org/core/repair for recovery instructions.
*************
Thu Dec  5 14:42:47.209 [initandlisten] exception in initAndListen: 12596 old lock file, terminating
Thu Dec  5 14:42:47.209 dbexit: 
Thu Dec  5 14:42:47.209 [initandlisten] shutdown: going to close listening sockets...
Thu Dec  5 14:42:47.209 [initandlisten] shutdown: going to flush diaglog...
Thu Dec  5 14:42:47.209 [initandlisten] shutdown: going to close sockets...
Thu Dec  5 14:42:47.209 [initandlisten] shutdown: waiting for fs preallocator...
Thu Dec  5 14:42:47.209 [initandlisten] shutdown: closing all files...
Thu Dec  5 14:42:47.209 [initandlisten] closeAllFiles() finished
Thu Dec  5 14:42:47.209 dbexit: really exiting now

Note: MongoDBs data files are usually located at /data/db but in my Ubuntu installation they where in /var/lib/mongodb.

Repair preserving data:

sudo mkdir /var/lib/mongodb0
sudo mongod --dbpath /var/lib/mongodb --repair --repairpath /var/lib/mongodb0
sudo mongod --dbpath /var/lib/mongodb0

Now that the server is up with a repaired version (/var/lib/mongodb0) of your original data (from /var/lib/mongodb) use mongo client to verify that everything is OK. In that case replace /var/lib/mongodb with /var/lib/mongodb0.

sudo rm -rf /var/lib/mongodb
sudo mv /var/lib/mongodb0 /var/lib/mongodb
sudo chown -R mongodb:mongodb /var/lib/mongodb

Repair without preserving data:

sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --dbpath /var/lib/mongodb --repair

When this completes, the repaired data files will replace the original data files in the /var/lib/mongodb directory.

Ref: http://docs.mongodb.org/manual/tutorial/recover-data-following-unexpected-shutdown/

Install MongoDB in Ubuntu 12.04 with PHP driver

Install MongoDB:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
sudo apt-get update
sudo apt-get install mongodb-10gen

Install MongoDB PHP driver:

sudo apt-get install php-pear php5-dev
pecl search mongo
sudo pecl install mongo

Configure MongoDB PHP driver: Create a file called /etc/php5/mods-available/mongo.ini with this content:

extension=mongo.so

And create a symlink to it in /etc/php5/conf.d/:

cd /etc/php5/conf.d
sudo ln -s ../mods-available/mongo.ini 20-mongo.ini

Then restart Apache:

sudo service apache2 restart

Start, stop and restart MongoDB:

sudo service mongodb start
sudo service mongodb stop
sudo service mongodb restart

Configuration file:

/etc/mongodb.conf

Log file:

/var/log/mongodb/mongodb.log

Data files:

/var/lib/mongodb

Ref: http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/

  • Page 1 of 2
  • 1
  • 2
  • >