问题
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 ?
回答1:
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.
回答2:
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.
回答3:
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
Mongoid
回答4:
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.
回答5:
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.
回答6:
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.
回答7:
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
回答8:
I used both of them and they are about to equals in functionality, but look at it's code stats
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
回答9:
I think Mongoid is much better at configuration and mapping.
回答10:
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.
回答11:
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
回答12:
Devise did not support MongoMapper, and I too prefer moving in the Rails3 way. So I switched to mongoid.
回答13:
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
回答14:
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.
来源:https://stackoverflow.com/questions/1958365/mongoid-or-mongomapper