Thin layer over the ruby driver that allows you to quickly grab hold of your data.
Ruby Shell
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
lib upgrade version to 0.7.0 Mar 15, 2016
script drop support for rubies older than 2.0.x Dec 11, 2016
spec fix a spec for newer versions of mongo's explain Dec 11, 2016
.gitignore Added handy scripts and optionally used gh mongodb port if available. Jul 3, 2013
.rspec
.ruby-version use ruby 2.2.4 by default Dec 11, 2016
.travis.yml drop support for rubies older than 2.0.x Dec 11, 2016
Gemfile drop support for rubies older than 2.0.x Dec 11, 2016
Guardfile Added guard. Oct 10, 2012
LICENSE Added a license. May 18, 2010
README.md Update readme and query for new mongo client. Dec 28, 2012
Rakefile
UPGRADES
plucky.gemspec Add homepage to gemspec and update file manifests to use git Apr 20, 2012
specs.watchr

README.md

Plucky

Thin layer over the ruby driver that allows you to quickly grab hold of your data (pluck it!).

Install

gem install plucky

Examples

connection = Mongo::MongoClient.new
db = connection.db('test')
collection = db['users']
collection.remove # clear out the collection

collection.insert({'_id' => 'chris', 'age' => 26, 'name' => 'Chris'})
collection.insert({'_id' => 'steve', 'age' => 29, 'name' => 'Steve'})
collection.insert({'_id' => 'john',  'age' => 28, 'name' => 'John'})

# initialize query with collection
query = Plucky::Query.new(collection)

puts 'Querying'
pp query.where(:name => 'John').first
pp query.first(:name => 'John')
pp query.where(:name => 'John').all
pp query.all(:name => 'John')

puts 'Find by _id'
pp query.find('chris')
pp query.find('chris', 'steve')
pp query.find(['chris', 'steve'])

puts 'Sort'
pp query.sort(:age).all
pp query.sort(:age.asc).all # same as above
pp query.sort(:age.desc).all
pp query.sort(:age).last # steve

puts 'Counting'
pp query.count # 3
pp query.size # 3
pp query.count(:name => 'John')       # 1
pp query.where(:name => 'John').count # 1
pp query.where(:name => 'John').size  # 1

puts 'Distinct'
pp query.distinct(:age) # [26, 29, 28]

puts 'Select only certain fields'
pp query.fields(:age).find('chris')   # {"_id"=>"chris", "age"=>26}
pp query.only(:age).find('chris')     # {"_id"=>"chris", "age"=>26}
pp query.ignore(:name).find('chris')  # {"_id"=>"chris", "age"=>26}

puts 'Pagination, yeah we got that'
pp query.sort(:age).paginate(:per_page => 1, :page => 2)
pp query.sort(:age).per_page(1).paginate(:page => 2)

pp query.sort(:age).limit(2).to_a           # [chris, john]
pp query.sort(:age).skip(1).limit(2).to_a   # [john, steve]
pp query.sort(:age).offset(1).limit(2).to_a # [john, steve]

puts 'Using a cursor'
cursor = query.find_each(:sort => :age) do |doc|
  pp doc
end
pp cursor

puts 'Symbol Operators'
pp query.where(:age.gt => 28).count       # 1 (steve)
pp query.where(:age.lt => 28).count       # 1 (chris)
pp query.where(:age.in => [26, 28]).to_a  # [chris, john]
pp query.where(:age.nin => [26, 28]).to_a  # [steve]

puts 'Removing'
query.remove(:name => 'John')
pp query.count # 2
query.where(:name => 'Chris').remove
pp query.count # 1
query.remove
pp query.count # 0

Help

https://groups.google.com/forum/#!forum/mongomapper

Contributing

  • 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

Copyright (c) 2010 John Nunemaker. See LICENSE for details.