Skip to content

akdubya/arel-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

arel-mongo

An experimental MongoDB engine for Arel.

A Quick Tour

Arel::Collection is comparable to Arel::Table. Collections may be initialized with attributes for typecasting:

users = Collection.new(:users,
  :attributes => [[:name, Attributes::String, :profile, Attributes::Hash]])

users.insert([{ :name => 'bob', :profile => { :location => 'Earth', :rating => 1 } }])

The standard Arel predicates and operators work as expected.

users.where(users[:name].eq('bob'))
# => { users[:_id] => ..., users[:name] => 'bob', users[:profile] => {...} }

But this would all be pointless without support for embedded documents,

users.where(users['profile.location'].eq('Earth'))
users.where(users[:profile].elem(users['profile.rating'].gte(1), users['profile.location'].eq('Earth')))

and Mongo-specific predicates:

users.where(users[:name].exists(true))

Arel Mongo also supports MongoDB cursors with efficient caching thanks to Hamster.

What about atomic updates?

users.where(users[:name].eq('bob')).update(users['profile.rating'].incr(1))

Sweet!

Status

This is a conversation-starter for now.

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 © 2010 akdubya. See LICENSE for details.

About

A MongoDB engine for Arel

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages