0.0
No commit activity in last 3 years
No release in over 3 years
Adds scope methods to Mongo::Collection. Inspired by Searchlogic.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
 Project Readme

MongoScope¶ ↑

Hacking on some scope methods for MongoDB in Ruby. Inspired by Searchlogic.

Adds a scope method, as well as helper methods for MongoDB operators.

Installation¶ ↑

Hosted on Gemcutter

$ gem install mongo_scope

Example ¶ ↑

From the examples dir

# Mongod should be running locally

require 'rubygems'
require 'mongo'
require 'mongo_scope'

# get a collection
connection = Mongo::Connection.new
db   = connection.db('ruby-mongo-test')
coll = db.collection("test")

# Add some data
coll.remove
coll.save({:first_name => 'Mike', :last_name => 'Harris', :age => 27})
coll.save({:first_name => 'Lowell', :age => 28})
coll.save({:first_name => 'Lou', :age => 27})

# using a scope helper method (find works just like the normal Mongo::Collection find)
puts coll.scope_in(:first_name => ['Mike','Lowell']).find.count # 2
puts coll.scope_gt(:age => 27).find.count # 1

# chained scopes
puts coll.scope_eq(:first_name => /^L/).scope_eq(:age => 27).find.count # 1

# the raw scope method (this is wrapped by the helper methods)
puts coll.raw_scope(:op => '$in', :field => :first_name, :val => ['Mike','Lowell']).find.count # 2

Copyright © 2009 Mike Harris. See LICENSE for details.