https://github.com/endel/mongo-sugar
Syntactic Sugar for Official MongoDB Driver
https://github.com/endel/mongo-sugar
Last synced: about 1 year ago
JSON representation
Syntactic Sugar for Official MongoDB Driver
- Host: GitHub
- URL: https://github.com/endel/mongo-sugar
- Owner: endel
- License: mit
- Created: 2012-12-01T22:40:38.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2012-12-02T00:11:32.000Z (over 13 years ago)
- Last Synced: 2024-04-25T21:21:24.013Z (about 2 years ago)
- Language: Ruby
- Homepage: http://endel.github.io/mongo-sugar/
- Size: 113 KB
- Stars: 0
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Mongo Sugar [](http://travis-ci.org/endel/mongo-sugar)
===
Provide a syntatic sugar for official MongoDB ruby driver, similar to an ORM.
But it isn't another ORM. If you need relationship features, you should use
[MongoID](http://mongoid.org/), [MongoMapper](http://mongomapper.com/), or, why
not - a relational database.
Usage
===
Add mongo-sugar to your gemfile:
gem 'mongo-sugar'
Require it on your code:
require 'mongo-sugar'
Define classes as collections. By default, collection names are the class name
underscored. On the following example, the collection name is `my_collection`.
class MyCollection < Mongo::Sugar::Collection
#
# Define your custom methods, like this:
#
def do_upsert(hash)
@collection.update({
key: hash[:key]
}, {
:$addToSet => {
:value => hash[:value]
}
}, :upsert => true)
end
end
You can customize the collection names using `store_in`, which is similar to mongoid
syntax.
class MyCollection < Mongo::Sugar::Collection
store_in :collection => 'custom_collection'
end
For more details, read the [documentation](http://rubydoc.info/github/endel/mongo-sugar/master/frames) here.
License
===
This library is released under MIT License. Please see LICENSE file.