Giter Club home page Giter Club logo

dm-mongo-adapter's Introduction

DataMapper MongoDB Adapter

<img src=“http://travis-ci.org/mbj/dm-mongo-adapter.png?branch=master” />

Status

The adapter is going through a major re-work as DataMapper will soon support EmbeddedValue (see: wiki.github.com/datamapper/dm-core/roadmap) and the adapter will significantly benefit from that fact as there won’t be a need to hack around DM’s private API like it used to be. Apart from embedded docs support there’s plenty of work that needs to be done around MongoDB’s modifier operators (www.mongodb.org/display/DOCS/Updating). With these things done we can start thinking about releasing 1.0.

Contributors are most welcome! In case of any questions you can find me on #datamapper IRC channel.

solnic

Useful links:

Dependencies

Ruby gems

  • dm-core ~> 1.3.0.beta

  • dm-aggregates ~> 1.3.0.beta

  • dm-migrations ~> 1.2.0.beta

  • mongo ~> 1.5.0

  • mongodb ~> 2.0.0 (This gem is only tested against this version)

Install

gem install dm-mongo-adapter

Synopsis

DataMapper.setup(:default,
  :adapter  => 'mongo',
  :database => 'my_mongo_db',
)

# Define resources
class Student
  include DataMapper::Mongo::Resource

  property :id, ObjectId
  property :name, String
  property :age, Integer
end

class Course
  include DataMapper::Mongo::Resource

  property :id, ObjectId
  property :name, String
end

# No need to (auto_)migrate!
biology = Course.create(:name => "Biology")
english = Course.create(:name => "English")

# Queries
Student.all(:age.gte => 20, :name => /oh/, :limit => 20, :order => [:age.asc])

# Array and Hash as a property
class Zoo
  include DataMapper::Mongo::Resource

  property :id, ObjectId
  property :opening_hours, Hash
  property :animals, Array
end

Zoo.create(
  :opening_hours => { :weekend => '9am-8pm', :weekdays => '11am-8pm' },
  :animals       => [ "Marty", "Alex", "Gloria" ])

Zoo.all(:animals => 'Alex')

DataMapper plugins

Currently the adapter is known to work with:

  1. dm-timestamps

  2. dm-validations

  3. dm-aggregates

  4. dm-pager

  5. dm-serializer

  6. dm-types

  7. dm-is-tree

and expect more of course :)

Authors and contributors

The adapter has been originally written by Shane Hanna (shanna). Project is currently maintained by Piotr Solnica (solnic).

Contributors:

  • Anthony Williams (antw)

  • Lance Carlson (lancecarlson)

  • Markus Schirp (mbj)

Note on Patches/Pull Requests

  • Fork the project.

  • Make your feature addition or bug fix.

  • Add tests for it. This is important so I don’t break it in a future version unintentionally.

  • 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 I can ignore when I pull)

  • Send me a pull request. Bonus points for topic branches.

Copyright © 2009 “Shane Hanna”, 2009-2010 “Piotr Solnica”. See LICENSE for details.

dm-mongo-adapter's People

Contributors

dkubb avatar lancecarlson avatar shanna avatar shingara avatar solnic 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

dm-mongo-adapter's Issues

DBRef defaults are wrong

DBRef should not have the default field name "_id" (collision with Models ObjectID)
DBRef should not default to be a key (creates an unwanted cpk)

Fixed and speced this in my pull request.

Not compatible with the latest versions of dm-core?

I'm having trouble using the mongo adapter now that I have gem installed dm-migrations. This seems to have installed a newer version of dm-core and out of the box this doesn't seem to be compatible.

I managed to make it install by changing the requirements in the Rakefile and changing line 182 of query.rb. It declared a method with the method name on the next line, which seems wrong, but then I'm a ruby noob so I could just not understand some language feature you were using.

BSON::InvalidKeyName not caught on #update

BSON rejects hash keys with periods. When you try to BSON-serialize a ruby Hash containing illegal keys, BSON::InvalidKeyName should be raised. When creating a new DataMapper::Mongo::Resource containing such a hash, the error is handled correctly:

class Sample
  include DataMapper::Mongo::Resource
  property :id, ObjectId
  property :data, Hash
end
DataMapper.finalize

invalid_hash = {'bad.key' => 1}
valid_hash = {'good_key' => 1}

Sample.create(:data => invalid_hash)
#=> BSON::InvalidKeyName: bad.key - key must not contain '.'

But if we create a valid resource then later update it with an invalid hash, the failure is silently dropped.
The resource appears to have been persisted, even though Mongo never accepted the data:

a = Sample.create(:data => valid_hash)
#=> #<Sample @id=BSON::ObjectId('4fce0d32faa3171f99000004') @data={"good_key"=>1}>

a.update(:data => invalid_hash)
#=> true

a.data
#=> {"bad.key"=>1}

a.persisted?
#=> true

a.dirty?
#=> false

b = Sample.first
#=> #<Sample @id=BSON::ObjectId('4fce0d32faa3171f99000004') @data={:good_key=>1}>

a == b
=> true

Finalize under dm-rails

Hello,

I created a fresh rails 3.0 app with dm-rails and I am trying to use mongo-adapter. Here is what I get:

/Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-core-1.0.0/lib/dm-core.rb:327:in finalize_model': DataMapper::Mongo::EmbeddedResource must have at least one property or many to one relationship to be valid (DataMapper::IncompleteModelError) from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-core-1.0.0/lib/dm-core.rb:309:infinalize'
from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-core-1.0.0/lib/dm-core/model/descendant_set.rb:33:in each' from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-core-1.0.0/lib/dm-core/model/descendant_set.rb:33:ineach'
from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-core-1.0.0/lib/dm-core.rb:308:in finalize' from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-rails-1.0.0/lib/dm-rails/setup.rb:43:infinalize'
from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-rails-1.0.0/lib/dm-rails/setup.rb:50:in preload_models' from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/dm-rails-1.0.0/lib/dm-rails/railtie.rb:83:in_callback_before_7'
from /Users/juggy/.rvm/gems/ruby-1.8.7-p174/gems/activesupport-3.0.0.beta4/lib/active_support/callbacks.rb:423:in `_run_prepare_callbacks'

I have a single Mongo::Resource defined, no EmbeddedResource. When I do create an EmbeddedResource, it then seems to work.

I use the git master as the gem to run this.

Thanks,
Julien.

"DBRef" property name is misleading

There is a convention about a "DBRef" in mongo. dm-mongo-adapter does not follow this convention so the property should not be named after it.

Suggestion:

Rename DBRef it to ObjectId, and rename ObjectId to some better name g.

I read the irclogger, there was a discussion about a "universal general record identifiing cross datastore property" month ago. Maybe this issue is related to this discussion.

EmbeddedResources cannot have complex properties or embedments

Defining a property of type Hash or Array in an embedded document causes the following error: "[...] property.rb: `initialize': +type+ was Hash, which is not a supported type (ArgumentError)".

And it would be nice to chain embedded documents, but the method "embeds" is not defined for an EmbeddedResource.

Thank you, this really rocks (-;

execute db.auth

Hello,

How can I execute mongo's db.auth with your adapter?

I think it shouldn't be necessary but for some reasons I keep getting:
cursor.rb:86:in `next_document': unauthorized db:db_name lock type:-1 client:127.0.0.1 (Mongo::OperationFailure)

Thanks!

undefined method `timestamps'

NoMethodError: undefined method `timestamps' for Book:Class

Adding dm-timestamps 10.2... it doesnt seem to recognize the timestamps :at command on my models

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.