GithubHelp home page GithubHelp logo

mongomapper's Introduction

MongoMapper

A Ruby Object Mapper for Mongo.

RubyGems

Build Status

Install

$ gem install mongo_mapper

Documentation

http://mongomapper.com/documentation/

http://rdoc.info/github/mongomapper/mongomapper

Open Commit Policy

Like Rubinius, we're trying out an "open commit policy".

If you've committed one (code) patch that has been accepted and would like to work some more on the project, send an email to Scott Taylor [email protected] along with your commit sha1.

Compatibility

MongoMapper is tested against:

  • MRI 2.4 - 3.2
  • JRuby (Versions with 3.1 compatibility)

Additionally, MongoMapper is tested against:

  • Rails 5.0 - 5.2
  • Rails 6.0 - 6.1
  • Rails 7.0 - 7.1

Note, if you are using Ruby 3.0+, you'll need Rails 6.0+.

Contributing & Development

$ git clone https://github.com/mongomapper/mongomapper && cd mongomapper
$ bundle install
$ bundle exec rake
  • Fork the project.
  • Make your feature addition or bug fix. All specs should pass.
  • Add specs for your changes. This is important so that it doesn't break in a future version.
  • Commit, do not mess with Rakefile, version, or history. If you want to have your own version, that is fine but bump version in a commit by itself in another branch so a maintainer can ignore it when your pull request is merged.
  • Send a pull request. Bonus points for topic branches.

How to release

See HOW_TO_RELEASE.md

Problems or Questions?

Hit up the Google group: http://groups.google.com/group/mongomapper

Copyright

Copyright (c) 2009-2023 MongoMapper. See LICENSE for details.

Contributors

MongoMapper/Plucky is:

  • John Nunemaker
  • Chris Heald
  • Scott Taylor

But all open source projects are a team effort and could not happen without everyone who has contributed. See CONTRIBUTORS for the full list. Thank you!

mongomapper's People

Contributors

a2ikm avatar arthuraa avatar balexand avatar bearded avatar bkeepers avatar bmarini avatar brianhempel avatar bryckbost avatar cheald avatar danp avatar dcu avatar djsun avatar fcheung avatar gaffneyc avatar greatuserongithub avatar hamin avatar jherdman avatar jnunemaker avatar jpbougie avatar laserlemon avatar leifcr avatar mitsuboshi avatar mopp avatar mtsmfm avatar plasticlizard avatar sgnn7 avatar smtlaissezfaire avatar tjtuom avatar ujihisa avatar vangberg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongomapper's Issues

Should be able to create, build, etc. on associations

stuff like this should work:

  mm = Project.create(:name => 'MongoMapper')
  mm.statuses.build(params[:status])
  mm.statuses.create(params[:status])

  mm.statuses << Status.new(:name => 'mm1')
  mm.statuses.push Status.new(:name => 'mm1')

Allow defaulting the :fields selected by any find

Once documents start getting big they are slow to query unless you define the fields you want to return. Having a default list of keys to select would be handy. Maybe something like this would work:

class Foo
  include MongoMapper::Document
  default_keys :fname, :lname # etc, etc
end

Doing the above would mean that any find query would only select fname, lname, etc unless otherwise specified.

Nothing in _type

I have Message, Enter and Exit inherit from it. If I create a Enter document, I have nothing in _type. But if I create it in the association array, it works :

>> Enter.create # It doesn't work
>> r=Room.create
>> r.messages << Enter.create # It works

Wrong results with polymorphic associations

Hi,

I have a model Message, Enter and Exit derived from it. I create one document for each, then I want all the Enter documents. But the result is wrong and I have all the documents but with the right _type (Enter for one, Exit for the other) :


>> r=Room.create
>> r.messages = [Enter.create, Exit.create]
>> Enter.all
=> [ #< Enter updated_at: Thu Aug 06 14:20:43 UTC 2009, _id: 4df37cd94a7ae6bb00000068, _type: Enter, created_at: Thu Aug 06 14:20:43 UTC 2009>, #< Enter updated_at: Thu Aug 06 14:28:06 UTC 2009, _id: 4df37cd94a7ae87600000068, _type: Exit, created_at: Thu Aug 06 14:28:06 UTC 2009>]

But I just want the Enter documents.

NB : If I do Enter.create without passing it in the association I have nothing in _type, but I'm gonna create another issue for that.

Document does not persist its embedded document's set of embedded documents

should "store embedded documents from the embedded document" do
  @document = Class.new do
    include MongoMapper::Document
    many :people
  end

  sparky = Pet.new(:name => "Sparky", :species => "Dog")
  meg = Person.new(:name => "Meg", :pets => [sparky])
  doc = @document.new :people => [meg]

  doc.people.first.pets.first.should == sparky
end

Doesn't work without driver extensions

I tried versions 0.2.0 and 0.3.1 of MongoMapper with versions 0.9, 0.10.0 and 0.10.1 of the MongoDB Ruby driver and got the same error every time:

/usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/util/bson.rb:77:in `serialize': wrong number of arguments (2 for 1) (ArgumentError) from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/util/bson.rb:77:in`serialize' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/message/message.rb:62:in `write_doc' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/message/query_message.rb:67:in`initialize' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:215:in `new' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:215:in`send_query_if_needed' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:195:in `refill_via_get_more' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:179:in`num_remaining' from /usr/local/lib/ruby/gems/1.8/gems/mongodb-mongo-0.10.1/lib/mongo/cursor.rb:56:in `next_object'

Nested :many embedded documents not saving

Suppose I have a Project which embeds people, and each� person embeds images.

person = Person.new
person.images << image
project = Project.new
project.people << person
project.save

Project.find(project.id).people.first.images.first.any? # false

I've created a gist for a failing association test: http://gist.github.com/150095

Use of :all or :in in find with array causes error

For :

Page.all(:conditions => { 'entities.uri' => { '$all' => ['Blah'] }}).each do |page|

An error is raised :

RuntimeError ($all requires array):
/usr/lib/ruby/gems/1.8/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb:68:in next_object' /usr/lib/ruby/gems/1.8/gems/mongodb-mongo-0.9/lib/mongo/cursor.rb:117:into_a'
/usr/lib/ruby/gems/1.8/gems/jnunemaker-mongomapper-0.2.0/lib/mongomapper/document.rb:144:in find_every' /usr/lib/ruby/gems/1.8/gems/jnunemaker-mongomapper-0.2.0/lib/mongomapper/document.rb:48:inall'

The same error occurs with $in too.

Change belongs_to to use db references

Then we don't have to do lots of queries to pull them out.

I'm thinking belongs_to :user would create two keys: :user_id and :user_reference.

  • user_id would work just like it does now.
  • user_id= would set user_id and user_reference.
  • user would return db referenced object wrapped in new User instance (User.new(db referenced attributes).
  • user= would set user_id and user_reference.

Something like that should work.

Reconcile finder options for count and find

Finder methods currently sanitize the conditions hash and map an array to a Mongo $in condition. The count method with the same arguments does not do this.

Finder options might be too heavy for count. Should we make convert_conditions public so we can call it in the count case?

Separate unit and functional tests

Write now I just have a bunch of tests. I want to separate those that are unit from those that are more functional, such as hitting the database.

update_attributes does not return false on failed save

When obj.update_attributes fails to save (ie due to validation) the obj is returned instead of false. This causes validation messages not to work on updates in the rails view. For Example:

def update
  @note = Note.find(params[:id])
  if @note.update_attributes(params[:note])
    redirect_to @note
  else
    render 'edit'
  end
end

Just redirects if the validation fails instead of rendering 'edit' because the note object is returned.

irb example:

>> note.update_attributes(:title => '')
=> #<Note _id: bf8601aa4a7dd708000000eb, created_at: 2009-08-08 19:50:32 UTC, updated_at: 2009-08-08 20:25:44 UTC, title: , body: this is note 1, tags: []>

Advance Query

Will be beautifull if is possible query like that

    Account.find(:conditions => { :any => /full_text_search/i })

Where ANY are All fields of the document

Then like others ticket:

    Account.find(:conditions => "account_details.age > 10")

Then I thinks is necessary a way for "shortcut" conditions, because in some cases hash will be very very very long so I think we can use the "where" clause of mongo with a direct string like:

    Account.find("account_details.age > 16 OR orders.size > 10")

validation option :if with symbol fails

Basically validatable doesn't support the symbol to proc stuff. I'm adding the issue here because github won't let me add it on jnunemaker-validatable for some reason.

Problem with additional keys in a child class

If I have a Message with a body and its child Enter with a key title that it's not in Message, I have an error when I retrieve all messages :


class Message
  include MongoMapper::Document

  key :body, String
end

class Enter < Message
  key :title, String
end

Enter.create(:body => "Body test", :title => "Title test")
Message.all # It breaks because title= is undefined in Message

use of :class_name breaks association storage

Using module namespaces and thus :class_name breaks document storage.

See namespaced version of test/test_associations.rb

http://gist.github.com/143944

rake test gives :

  1. Failure:
    test: Many documents should store the association. (AssociationsTest)
    [/usr/lib/ruby/gems/1.8/gems/jnunemaker-matchy-0.4.0/lib/matchy/built_in/operator_expectations.rb:30:in fail!' /usr/lib/ruby/gems/1.8/gems/jnunemaker-matchy-0.4.0/lib/matchy/built_in/operator_expectations.rb:20:in=='
    ./test/test_associations.rb:123:in __bind_1247168503_298757' /usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:incall'
    /usr/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:253:in test: Many documents should store the association. ' /usr/lib/ruby/gems/1.8/gems/mocha- 0.9.7/lib/mocha/integration/test_unit/gem_version_201_and_above.rb:20:inrun']:
    Expected 0 to == 1.

Allow for condition auto-detection when finding

I'd like to be able to do finds without passing :conditions. Just detect the conditions based on removing keys that we know are not related to conditions like select, fields, order, limit, offset, sort, etc.

  Article.first('tags.name' => %w(foo bar))

Make a simple way to override auto-generated id

Right now you could just define generate_id to do this but it might be nice to have some kind of API for doing it. Maybe...

class Foo
  include MongoMapper::Document
  id :some_id_method # or a proc or something?
end

If anyone has any thoughts on this, let me know.

Should be able to find on associations and keep scoping

stuff like this should work:

  mm = Project.new(:name => 'MongoMapper')
  mm.statuses = [Status.new(:name => 'mm1'), Status.new(:name => 'mm2')]
  mm.save
  hm = Project.new(:name => 'HappyMapper')
  hm.statuses = [Status.new(:name => 'hm1'), Status.new(:name => 'hm2')]
  hm.save

  mm.statuses.find(:all).collect(&:name).should == ['mm1', 'mm2']

Capped Collections

It would be pretty handy to be able to specify capped collections.

From what I understand they do need to be created when first creating the collection and can't be added later (like indexes or keys). Perhaps adding an option to the database method in the document?

So this is more just a ticket for the feature and perhaps thoughts on the best way to implement...

Support for long ints

It appears that MongoDB doesn't support anything larger than 4-byte ints. The ruby driver raises an error suggesting the use of a Double.

Perhaps not a great deal that can be done but raising anyway.

Group queries

This is a query ticket really, it doesn't look like the db.collection.group method is coded up at the moment. Are there any thoughts about how it would be added in. I was thinking it could be :

Collection.group( :ns => "coll", :key => { :a => true, :b => true }, :cond => {:active => 1}, :reduce => 'function(''obj'',''prev'') { prev.csum += obj.c; },', :initial => {:csum => 0} )

Or is there another way this is/could be tackled ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.