Installing and Updating MongoDB: Dev x Prod Envs - mongodb

I'm playing with MongoDB while reading O'Reilly MongoDB - The Definitive Guide.
In appendix A, the authors teach how to install MongoDB, downloading the latest version, creating a /data/db directory and so on.
The question is: what's the best approach to install MongoDB?
In my computer, first I extracted the archive and then, inside /mongodb-linux-i686-2.0.1 directory, I created that structure, /data/db. Did I take the right decision?
I'm just playing but, what if I decide to start a real project using MongoDB? How to setup properly my server, in order to update MongoDB for next releases without data loss (as my /data directory is inside /mongodb-linux-i686-2.0.1 directory)?

Ordinarily MongoDB will use /data/db -- that is, that folder in the root of your filesystem tree -- as the data path. You can override this with the --dbpath command-line argument, or in a config file (and with --config). It is up to you whether to use the default data path or a custom one, and to use a startup script that sets the options you want.
If you are using an RPM-based distribution, see http://www.mongodb.org/display/DOCS/CentOS+and+Fedora+Packages for information about using officially-provided 10gen RPMs; if you are using Debian or Ubuntu, see http://www.mongodb.org/display/DOCS/Ubuntu+and+Debian+packages instead. These packages come with startup scripts for you and defaults for --dbpath which match expectations of the respective operating systems.

Related

Meteor: mongoimport command not found

I'm using meteor and I need to use mongoimport to add some JSON-data to the DB. But when I try to start meteor import, I got the error command not found. This is surprising for me as mongoimport is part of mongoDB, so I expected this working.
So I guess I have to install MongoDB separately from meteor (using OS X). But what is the correct way to do that?
Of course I can do brew install mongodb. Or would it be better to download the mongodb-file manually, extract the archive and take the mongoimport-file?
I'm just worried to install mongodb, although I already have meteor installed and it works. I don't want to get two different mongoDB instances.
If you don't already have the mongoimport binary somewhere, just download MongoDB for OSX from their site, extract the archive somewhere, and use the mongoimport file that will be in its bin folder.
You won't get another daemon running unless you run another mongod and you are probably safest to avoid using brew so that it doesn't do something unintended.

Pyramid postgresql connection

I am totally new to pyramid.I am trying to develop an application that will use both pyramid angd postgresql but i am totally confused about how to configure the initializedb.py file in the sripts directory especially initializing the database.
I'm using PostgreSQL 9.1.
If I understand your question, you just need to find out where to configure the connection to DB. I assume you created a sqlAlchemy based project.
In the root of the pyramid app you can find the ini files. By default you should have development.ini and production.ini files. The former is used for development and the latter for production environment, so they can (and should) differ for some configurations.
In both files you should find a line like this:
sqlalchemy.url = sqlite:///%(here)s/dbname.sqlite
You just need to change that line with something like this:
sqlalchemy.url = postgresql://DBUser:DBPassword#DBHostNameOrIP:5432/DBName
(sustitute parameters as needed)
Whe you use initializedb.py directly, but you should use the initialize_YourProject_db script (in the bin folder, one dir back from the pyramid root), like this:
initialize_YourProject_db development.ini
where "YourProject" is the name of your project as defined when you created it and development.ini is the ini file you wish to use.
If have not done it yet, you may need to add 'db-psycopg2' to your required modules in setup.py and execute
pip install -e .
again (the final dot is not a typo).
Please remember that psycopg2 (the driver for postgresql) has dependencies (on ubuntu 14_04 you need a 'apt-get install libpq-dev python-dev', it may differ in other distros/SOs).
If enaything works fine, the script will create all tables referenced, according to your models, and insert all items defined in initializedb.py and added to the DBSession

Vagrant Berkshelf - Shelf Path?

Is it possible to set the path where the berkshelf plugin puts the cookbooks it installs? (As in the .berkshelf folder)
I am running Windows 7.
I am currently trying to install a mysql server using an opscode cookbook to a vm and here at work they have the %HOMEDRIVE% system variable set to a network drive. So when .berkshelf starts at the beginning of the Vagrantfile, it pushes the cookbooks to the network drive and it causes it to be slow and well, its not where it should be. Is there a fix to this?
VirtualBox did this as well, but I fixed it by altering the settings. I tried looking for some sort of equivalent settings for berkshelf, but the closest I got was for the standard berkshelf (thats not a vagrant plugin), it appears you can set this environment variable:
ENV['BERKSHELF_PATH']
Found here:
http://www.rubydoc.info/github/RiotGames/berkshelf/Berkshelf#berkshelf_path-class_method
I need to be able to have the cookbooks it reads from the berksfile store to my laptops local drive instead, as in my scenario I cannot have the mobility of the VM limited to the building because of files that are stored on the network.
Any incite would be much appreciated.
Perhaps its better to use the actual berkshelf over the vagrant plugin?
Thanks.
If you want to have the portability - a full chef-repo ready for chef-solo runs, better off using standalone berkshelf instead of the vagrant-berkshelf plugin - which is NOT that flexibly.
For complex cookbooks, I prefer to use standalone berkshelf as it allows me to do berks install --path chef/cookbooks to copy all cookbooks required from ~/.berkshelf/cookbooks, then I can just tar the whole thing and transfer to other machines for the same chef-solo run. some people use capistrano automate the tar and scp/rsync over the network. I just use rysnc/scp;-)
HTH

mongoDB, could not read from config file -- config in different folder / Uninstall it?

I'm very new to MongoDB and Mac in general. I installed mongoDB from the official site with a download package.
For all it's worth, given all the issues I'm having, I'd like to uninstall it and reinstall using Homebrew. Brew complains that mongoDB is already installed so I'm stuck at the moment.
From all the tutorials and online search, the config file should be installed in a /etc/ directory path. However, my mongodb.conf file is located in a very different file structure. I get a ERROR: could not read from config file each time I try running mongod.
This is where my config file is located:
/opt/sm/sets/versions/databases/head/mongodb/templates/mongodb.conf
How do I either :
Get the current version working (MongoDB shell version: 2.4.6)
Uninstall mongoDB entirely so I can install it with Homebrew (which seems a lot more straight forward)?
EDIT: I've also tried following this guide with no luck. http://www.mkyong.com/mongodb/how-to-install-mongodb-on-mac-os-x/
Thanks
Issue resolved with following steps (thanks to Karl Seguin's 'The Little MongoDB Book').
If you installed MongoDB via the download package from mongodb.org, you have to create create your own config file in /bin. Follow the instructions below
(copied from Karl Seguin's book):
download package
unzip package
Create a new text file in the bin subfolder named mongodb.config (if you have permission issues saving the file, save it first to your desktop then move file into folder).
Add a single line to your mongodb.config: dbpath=PATH_TO_WHERE_YOU_WANT_TO_STORE_YOUR_DATABASE_FILES.
For example, on Windows you might do dbpath=c:\mongodb\data and on Linux you might do dbpath=/var/lib/
mongodb/data.
Make sure the dbpath you specified exists
Launch mongod with the --config /path/to/your/mongodb.config parameter
For me, my launch path to the mongodb.config file was:
mongod --config /opt/sm/sets/versions/databases/head/mongodb/bin
(Note, this is to mongodb.config, not mongodb.conf file as many tutorials ask to point to.)
Hope this helps someone.
Link to Seguin's book(it's free): http://openmymind.net/mongodb.pdf
In windows if you want to run mongodb with config don't forget quotes to indicate location of mongo.config.
Example: if your mongod.exe is located in C:\Program Files\MongoDB\bin and you are located in that folder with prompt(with admin privileges) and supposing that mongo.config is in C:\Program Files\MongoDB run:
mongod.exe --config "C:\Program Files\MongoDB\mongo.config"
the extension of your config file does not matter but if you don't get it right it might not read from it.
if you used a text editor like notepad make sure the file extension is exactly the same.
else add .txt to the end /opt/sm/sets/versions/databases/head/mongodb/templates/mongodb.conf.txt
you must of have thought you saved it with a mongodb.conf while it was actually mongodb.conf.txt

Issues with meteor app on vagrant share

I have a vagrant VM (virtualbox) setup with meteor. My host and guest are both Ubuntu. The VM contains a vboxfs share folder setup through the Vagrantfile. The behavior I am noticing is similar to a NFS mount.
I am able to create a meteor project in this shared folder, but when I run the project I get errors pointing to mongodb.
If I follow instructions on
https://github.com/pixelhandler/vagrant-dev-env/blob/master/README.md
my app works just fine.
Upon further investigation it seems that MongoDB does not work on NFS shares, http://www.mongodb.org/display/DOCS/NFS
Has anyone else run in to this issue? and if so, have you figured out a (non-rsync) solution?
I plan to send link of this question to 10gen, perhaps someone from their team can answer it.
Not sure what Mongo's plans are re running on NFS / vboxfs, but you could work around this by running your own MongoDB not in the shared folder (eg, use the ubuntu mongodb package). Use the MONGO_URL environment variable to tell meteor where to connect. If you pass this variable, meteor will not try to start MongoDB in the meteor project directory.
You can move the data dir somewhere inside the VM, and use a symlink from the vagrant folder:
cd /vagrant/.meteor/local
ln -s ~/db/
This means the data will not be shared, but you probably want it git ignored anyway.
(https://grahamrhay.wordpress.com/2013/06/18/running-meteor-in-a-vagrant-virtualbox/)
grahamrhay's solution would not work with the vagrant box started on Windows. There is no way to make symbolic links on windows for vagrant, at least not for administrator accounts.