Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/petejkim/tinymongo
Simple MongoDB wrapper
https://github.com/petejkim/tinymongo
Last synced: about 1 month ago
JSON representation
Simple MongoDB wrapper
- Host: GitHub
- URL: https://github.com/petejkim/tinymongo
- Owner: petejkim
- License: mit
- Created: 2010-07-21T03:35:04.000Z (over 14 years ago)
- Default Branch: master
- Last Pushed: 2010-09-09T11:50:28.000Z (about 14 years ago)
- Last Synced: 2024-09-19T05:39:06.506Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 121 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: LICENSE
Awesome Lists containing this project
README
= TinyMongo
Simple MongoDB wrapper
== Notice
This gem is not yet ready for production use.
== Install
gem install tinymongo
== Rails Setup (Rails 3)
To create TinyMongo config file (config/tinymongo.yml) and initializer file (config/initializers/tinymongo.rb), do the following:
rails generate tinymongo
== Connecting To MongoDB directly (for non-Rails projects)TinyMongo.configure({:host => 'localhost', :database => 'db_name'})
TinyMongo.connect
== Exampleclass Person < TinyMongo::Model
mongo_collection :people # optional if using Rails
mongo_key :name
mongo_key :age, :default => 0
mongo_key :children, :default => []
def make_child
child = Person.create(:name => 'Baby')
push({:children => child}) # push child into children array
end
def grow_up
inc({:age => 1}) # increments age by 1
end
def set_stuff(n,a,c)
# don't forget to put self
self.name = n
self.age = a
self.children = c
save
end
end
Person.drop # empty person collection
p = Person.create(:name => 'John', :age => 20)
p.make_child
p.grow_up
Person.find.each do |person|
puts person.name
end
Person.find_one(:name => 'John').age
Person.create(:name => 'Jim')
Person.create(:name => 'Pam')Person.find.to_a.map { |person| person.name }
Person.find.has_next?Person.find.sort({:name => 1}).skip(2).limit(1).next!.name
Person.find({:name => 'John'}, {:age => 1}) # select only age field
Person.find.count # count ignores skip and limit
Person.find.skip(1).size # size is affected by skip and limit
Person.distinct(:name)
Person.ensure_index({:name => 1})
Person.drop_index({:name => 1})
== CopyrightCopyright (c) 2010 Peter Jihoon Kim. See LICENSE for details.