Sha256: bda051aec37cf9bea4c63f997c3273c43db88f4d02ee77d228148f9e9162fba0

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

= 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.scope(:op => '$in', :field => :first_name, :val => ['Mike','Lowell']).find.count # 2

== Copyright

Copyright (c) 2009 Mike Harris. See LICENSE for details.

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongo_scope-0.0.2 README.rdoc