Mongoid or MongoMapper? [closed]
Asked Answered
H

14

82

I have tried MongoMapper and it is feature complete (offering almost all AR functionality) but i was not very happy with the performance when using large datasets. Has anyone compared with Mongoid? Any performance gains ?

Heedful answered 24/12, 2009 at 13:43 Comment(0)
J
49

I have used MongoMapper for awhile but decided to migrate to MongoId. The reason is hidden issues plus arrogance towards users. I had to jump through hoops to make MongoMapper work with Cucumber (succeeded in the end) and to put a couple of patches even the project was simple, but it's not the point. When I tried to submit a bug fix (due to incompatibility with ActiveRecord), they seemingly got pissed off that I found a problem and I was pushed around. While I was testing, I also encountered a major bug with their query implementation, while their testing was tuned in a way that the tests pass. After my previous experience, didn't dare to submit it.

They have a significantly lower number of pull requests and bug/feature submissions than MongoId, i.e. community participation is much lower. Same experience as mine?

I don't know which one has more features right now, but I don't see much future in MongoMapper. I don't mind fixing issues and adding functionality myself, but I do mind situations when they wouldn't fix bugs.

Jointly answered 14/8, 2011 at 23:39 Comment(6)
Can I ask you, what was the major bug in the query implementation. I have used mongomapper in a previous project, but it was also my first exposure to mongo at all. Any information on specific issues with mongomapper you had would be great. ThanksRephrase
When getting first() without sorting, it works as last() instead (or visa versa). But the unit test is written in the way that it specifies order, so it passes. May be it's fixed by now, but I don't use MongoMapper anymore. But I doubt it, I saw how it was implemented, and it's a bad design.Jointly
Hi, can you send link for info about how to smoothly migrate from mongo mapper to mongoid?Chainey
@Jointly I dont thing it fixed yet I tried it gave me the same resultCabin
Thank God i saw this conversation was just deciding to use mongomapper or mongoid in my next big project. Guess Mongoid wins.Cityscape
We're thinking about migrating to Mongoid as well ... any suggestions? Did you run into any hurdles during the migration?Anopheles
B
40

i've been using both for the past couple weeks. Mongomapper has better support for relational associations (non-embedded) and has greater third-party support. Mongoid has better query support, much better documentation (MM has close to none, though a website is supposedly in the works), Rail 3 support (and thus Devise support) and a slightly more active community on Google Groups.

I ended up going with Mongoid.

Barbwire answered 22/7, 2010 at 19:8 Comment(2)
Since I originally wrote this answer Mongoid has picked up lots of third-party support and the difference in the communities is even greater. In my opinion Mongoid is more of a clear choice today. Performance should be relatively the same as they both go through the Ruby driver. Though you need to be careful with OM not to construct horrendous documents.Barbwire
MongoMapper's many-to-many is broken: github.com/jnunemaker/mongomapper/pull/259, github.com/jnunemaker/mongomapper/issues/488 +1 for MongoidErvinervine
H
37

Differences

MongoMapper

  • Claimed to have better support for relational associations.
  • Claimed to be more extensible because of it's plugin architecture.
  • Uses a DSL for querying.
  • Many-to-many associations are updated only one-sided in MongoMapper.
  • Less robust support for embedded documents. Updates the entire model even if only a few attributes are modified.

Mongoid

  • Suggested to be faster than MongoMapper by anecdotal evidence.
  • More robust support for embedded documents, using MongoDB atomic operations ($set, $push, $pull, etc.) to update nested documents in-place.
  • Supports bidirectional many-to-many associations.
  • Uses a chainable ARel-like syntax for querying.

Similarities

  • Both MongoMapper and Mongoid have websites with good documentation. MongoMapper was long claimed to have bad documentation, but their new website seems to close the gap.
  • Both can be configured through a YAML file, and both have a rails generator for that file.
  • Both are fully Rails 3 compatible.

Configuration

MongoMapper

defaults: &defaults
  host: 127.0.0.1
  port: 27017

development:
  database: database_name

Mongoid

development:
  sessions:
    default:
      database: database_name
      hosts:
        - 127.0.0.1:27017

3rd Party Libraries

Both sides have claimed to have better 3rd party support. Github reveals the following:

  • Searching for "Mongoid" yields 12671 results.
  • Searching for "MongoMapper" yields 4708 results.

Notably, Devise does not support MongoMapper.

Commit Activity

Over the last year, it looks like Mongoid has been more regularly maintained and updated than MongoMapper.

MongoMapper

MongoMapper

Mongoid

Mongoid

Hornswoggle answered 28/12, 2012 at 3:15 Comment(1)
Mongoid currently supports identity maps.Hew
V
9

A difference I found is that update_attribute in MongoMapper appears to write the whole document, regardless of what attributes actually changed. In Mongoid it only writes the changed attributes. This can be a significant performance issue for large records. This is particularly true for embedded documents (here labels), e.g.

profile = Profile.find(params[:id])
label = profile.labels.find_or_create_by(idx: params[:idx])
# MongoMapper doesn't have find_or_create_by for embedded docs
# -- you'll have to write custom code
profile.save

On save, MongoMapper will save the whole profile record, but MongoId will use the $set operator with positional logic to only update the label that changed.

Another issue is selecting which fields to return. Both support an only criterion, but Mongoid also supports a without criterion, which is natively supported by Mongo.

It appears to me that Mongoid just is more "rounded" and complete in its API, which probably explains that it's a larger code base. It also appears documented better.

Vesicatory answered 25/4, 2012 at 6:14 Comment(0)
N
7

Did you install mongo_ext? I think the performance is more related to the driver than the mapper itself. When looking at the mongo log, I can see without the extension, that the transer seems to have some lags.

Also do as they recommend on the monogdb site, select only the fields you need.

Northeastwards answered 25/12, 2009 at 5:42 Comment(2)
ruby driver is not that fast especially 1.8 but 1.9 just boosts the performance! i am just wondering if mongoid is more optimized or the only thing it offers is a different approach to quering and stuff for the time being mongomapper is almost feature complete offering almost all AR sugarHeedful
Note to those reading this over a year later: mongo_ext is no longer needed and has been rolled into the basic mongo gem.Harvell
H
4

Did some testing with MongoMapper last week, it was stable but I found the query interface a little limited (also some of the AR logic was quirky), switched to Mongoid today and it feels much better to use - and more intuitive if you are used to AR.

No speed conclusions yet - but the switch over was painless - it works with Rails 3 too.

Hebbe answered 20/7, 2010 at 18:12 Comment(0)
N
4

If you're using Rails3 I'd recommend Mongoid -- it also uses "include" instead of inheritance "<" to persist classes -- using "include" is the better paradigm in Ruby for adding persistence. Mongoid works fine for me with Devise.

To improve performance, try to selectively use the lower-level access, e.g. Moped - I've seen this to be up to 10x faster

Neuromuscular answered 31/3, 2011 at 11:42 Comment(0)
A
3

I think Mongoid is much better at configuration and mapping.

Attract answered 13/9, 2010 at 19:0 Comment(2)
I think so too. Besides that it feels closer to NoSQL than MongoMapper that it makes you think more in terms of ActiveRecord and therefore SQL. Another plus is the great documentationHeedful
Yep! Mongoid website rocks with documentation!Attract
A
2

I used both of them and they are about to equals in functionality, but look at it's code stats Mongoid vs MongoMapper

It looks like MongoMapper has much better code quality (if it does the same with less).

You can calculate this stats by Yourself, here's the analyzer https://github.com/alexeypetrushin/code_stats

Albright answered 3/8, 2011 at 20:13 Comment(8)
Key point: 'if it does the same with less'...Harvell
This seems completely unfounded.Prankster
Can you explain more please? Is this the same project using each of those libraries? Is it an average character count across all github projects? From looking at this chart, couldn't I argue that people are writing much more complex projects using MongoID than using MongoMapper? (just asking. I'm actually a MM user right now)Brew
> Is this the same project using each of those libraries? It's a comparison of the size of source code of MongoMapper & Mongo.Albright
Comparing the code quality of a project through code size is like comparing the quality of 2 cars by measuring the weight.Verdun
Actually comparing weight of cars is perfectly valid - You can make a lots of judgment - how fast it is, how much it takes gasoline, and so on. And, actually it is makes sense from scientific point of view, take a look at "Kolmogorov complexity".Albright
Still, altough some have greatly improved mongomapper's speed (coffeepowered.net/2013/07/29/…), it is still known and accepted that mongoid is faster.Hoskins
Another thing regarding the comparison to the cars: they both use different engines so weighting just the car without the weight of their drivers (moped vs 10gen) doesn't mean a thing. Again, speed and how code is mantained (taken care): these are the only thing that matters i a project.Hoskins
S
0

sudo gem install mongo_ext is key to getting performance.

MongoDB blows away CouchDB in terms of raw speed – though CDB does have its own set of advantages.

Benchmark: http://www.snailinaturtleneck.com/blog/?p=74

Stibine answered 25/12, 2009 at 5:45 Comment(2)
He's talking about mongoid x mongo_mapper, what is the faster ruby gem to access mongo, not mongodb x couchdb.Visibility
Note to those reading this over a year later: mongo_ext is no longer needed and has been rolled into the basic mongo gem.Harvell
S
0

I would expect performance to be the same, last time I checked MongoMapper lacked Rails 3 support - so I am looking at Mongoid for now.

Seppala answered 13/6, 2010 at 15:44 Comment(0)
G
0

Devise did not support MongoMapper, and I too prefer moving in the Rails3 way. So I switched to mongoid.

Gwenn answered 26/2, 2011 at 19:31 Comment(1)
I think MM currently supports it.Hew
Q
0

Mongoid is having a full support with Rails3 and having identity map feature.

More document is at http://mongoid.org

See the performance here http://mongoid.org/performance.html

Quinquereme answered 26/8, 2011 at 10:8 Comment(0)
T
0

I hope Below points add values to above answers.

1.Mongoid is completely Rails 3 compatible, and uses ActiveModel all over the place (validations, serialization, etc), where MongoMapper is still focused on Rails 2 and uses the validatable gem for its validations.

2.Mongoid officially supports and works on Ruby 1.8.7, 1.9.1, and 1.9.2 head.

3.Mongoid supports embedded documents more robustly, performing the MongoDB atomic operations on any area of the hierarchy internally. ($set, $push, $pull, etc). With MM you need to explicitly tell it to do these operations.

4.MongoMapper has better relational association support and works like this as default.

5.MongoMapper is more extensible, with a plugin architecture that makes it pretty easy for people to extend it with their own libraries. Mongoid does not have this.

6.MM supports identity maps, Mongoid does not.

7.MM has a larger community, and probably more 3rd party library support. I went crazy on documentation and rdoc.

8.Mongoid supports Master/Slave replication clusters. (Writes to master, round robin reads to slaves) MM does not.

9.Mongoid has an extremely rich ARel style criteria API, MM use AR2 style finders.

Tillie answered 14/11, 2013 at 6:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.