Mongoid or MongoMapper? [closed]

2019-01-30 03:57发布

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 ?

14条回答
来,给爷笑一个
2楼-- · 2019-01-30 04:00

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

查看更多
家丑人穷心不美
3楼-- · 2019-01-30 04:07

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.

查看更多
闹够了就滚
4楼-- · 2019-01-30 04:08

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

查看更多
戒情不戒烟
5楼-- · 2019-01-30 04:09

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

查看更多
时光不老,我们不散
6楼-- · 2019-01-30 04:12

I think Mongoid is much better at configuration and mapping.

查看更多
干净又极端
7楼-- · 2019-01-30 04:13

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.

查看更多
登录 后发表回答