Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongodb: What to know before using? [closed]

I'm starting a hobby (non-revenue) project using Ruby on Rails. I've done a fair amount of development in Rails using Postgresql, and I can make a pretty good imitation of normalized schema. However, Mongrodb looks shiny and new. What better for trying out something new than a hobby project?

Think back to when you started using Mongodb. What techniques did you learn later that made you say, "If only I knew that when I started!" What plug-ins did you discover that you would have used right from the start, if only you had known? What references would you like to have had bookmarked?

like image 516
Wayne Conrad Avatar asked Jan 23 '10 18:01

Wayne Conrad


People also ask

Is it necessary to close MongoDB connection?

There is no need for closing the connection explicitly. This way the application avoids creating and closing connections (which is an expensive operation).


2 Answers

I would definitely second the recommendation of MongoMapper if you're going to be using MongoDB with Rails. I will warn you, however, that there is (so far) no documentation other than a couple blog posts. If you're not comfortable digging into the source code to see how things work, it's probably not for you yet.

If you're working outside of Rails, I'd recommend staying away from MongoMapper. Because it's working MongoDB into something similar to what we expect from a SQL-backed ORM, it doesn't really give you a good idea of the power of and of the different thinking behind MongoDB. Spend some time playing around with the lower-level ruby driver, and even in the javascript console.

The other thing I'd recommend, especially since you mentioned knowing how to normalize a schema, is not to think of MongoDB as a database for now. The way you organize your data in MongoDB is very different that with a relational database. Try to think about it more as a place to store and retrieve Ruby hashes. You can do some relational things with MongoDB, but I'd recommend sticking with only self-contained documents while you're trying to wrap your head around NoSQL.

As for what links you should look at, I'd highly recommend reading through everything you can on the MongoDB site. Their documentation is very good. Particularly, take a look at the advanced queries, multikey indexes, and MapReduce to get an idea of some of the unique advantages and strengths of a NoSQL database.

like image 139
Emily Avatar answered Sep 29 '22 09:09

Emily


I am at nearly the same stage that you are. Starting a new project with MongoDB. I am around 7 weeks of experience. This is what I have found very useful:

Use Mongoid instead of Mongomapper

http://mongoid.org/

The documentation is excellent. Seriously, excellent. It should take you about 15 min reading all the documentation and you will have a very exact idea of what you can do and cannot do with Mongoid.

Tomorrow, the release candidate for a new major version of mongoid will be released. It is going to brings a lot of useful things.

I am using Rails 3. To install the development version add this to your gem file:

gem 'mongoid', "~>2.0.0.beta"

Current beta is 20, but as I said, tomorrow there is the release candidate.

Also I sugest you to join the google group as well. It has low traffic and people are very willing to answer any question. For example I showed them my first DB Model design and they gave me many ways to improve that. The creator of Mongoid answer your questions too.

In two words: Great community.

There is this plugin that enables you to use Machinist with mongo:

https://github.com/nmerouze/machinist_mongo

Works pretty well.

gem 'machinist_mongo', :require => 'machinist/mongoid',  :git => 'http://github.com/nmerouze/machinist_mongo.git', :branch => 'machinist2' 

You can use Forgery with Machinist. Awesome mix.

https://github.com/sevenwire/forgery

Another thing I want to say. I come from a relation database world, so this sounded really weird to at the beginning: You can save files in a mongo database.

In fact, it could be faster than managing them as we used to do. This is because of mongo's support for sharding. Sharding means that you can use a cluster of computers to serve the Mongo Database. It is seamless. Master-slave. So you can serve a file from many computers, each sending a portion. It scales very well :)

This is done using GridFS. http://www.mongodb.org/display/DOCS/GridFS

Mongoid supports that master-slave config.

Ask me if you need more information.

Edit:

Also: http://railscasts.com/episodes/238-mongoid

like image 20
Nerian Avatar answered Sep 29 '22 11:09

Nerian