https://github.com/eldoy/easymongo
Fast MongoDB client which makes using mongodb super easy
https://github.com/eldoy/easymongo
mongo mongodb mongodb-ruby-driver ruby rubygem
Last synced: about 1 month ago
JSON representation
Fast MongoDB client which makes using mongodb super easy
- Host: GitHub
- URL: https://github.com/eldoy/easymongo
- Owner: eldoy
- License: mit
- Created: 2017-07-11T22:01:51.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-08-22T12:45:06.000Z (almost 9 years ago)
- Last Synced: 2025-02-21T16:16:06.519Z (over 1 year ago)
- Topics: mongo, mongodb, mongodb-ruby-driver, ruby, rubygem
- Language: Ruby
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Easymongo
Super easy MongoDB Ruby client. This is the way mongo should be.
If you need something closer to pure Mongo, have a look at [Minimongo.](https://github.com/fugroup/minimongo)
We also have [Mongocore](https://github.com/fugroup/mongocore) if you're looking for a full ORM.
### Installation
```
gem install easymongo
```
or add to Gemfile.
### Usage
```ruby
# All commands supported
# https://docs.mongodb.com/ruby-driver/master/quick-start
# Connect
$db = Easymongo::Query.new(['127.0.0.1:27017'], :database => "easymongo_#{ENV['RACK_ENV']}")
# First
user = $db.users.get(:moon => 'animation').first
# Uses dot annotation
user.moon => 'animation'
user.name => 'Zetetic'
user.id => '596675a40aec08bfe7271e14'
user.bson_id => BSON::ObjectId('596675a40aec08bfe7271e14')
user.date => 2017-07-12 20:24:57 UTC
user.hello = 'Wake up' => Assign temporary value
# Very flexible, also works like this for last and count
user = $db.users.first
user = $db.users.first(:id => '596675a40aec08bfe7271e14')
user = $db.users.first('596675a40aec08bfe7271e14')
user = $db.users.first(:tv => 'tull')
user = $db.users.get(:food => 'healthy').first
# Last
$db.users.last
$db.users.last(:sun => 'close')
$db.users.get(:sun => 'close').last
# Count
$db.users.count
$db.users.count(:life => 'humancentric')
$db.users.get(:life => 'humancentric').count
# All
$db.users.all
$db.users.get.all
$db.users.all(:spread => 'knowledge')
$db.users.get(:earth => 'beautiful').all
# Insert / Update
result = $db.users.set(:space => 'unreal')
result.date => 2017-07-12 20:24:57 UTC
result.id => '596675a40aec08bfe7271e14'
result.bson_id => BSON::ObjectId('596675a40aec08bfe7271e14')
# Access Mongo result
result.ok? => true
result.n => 1
# All these methods work on the result
http://api.mongodb.com/ruby/current/Mongo/Operation/Write/Update/Result.html
# Delete
$db.users.rm('596675a40aec08bfe7271e14')
$db.users.rm(:satellites => 'fragile')
```
Created and maintained by [Fugroup Ltd.](https://www.fugroup.net) We are the creators of [CrowdfundHQ.](https://crowdfundhq.com)
`@authors: Vidar`