Skip to content

Fast MongoDB client which makes using mongodb super easy

License

Notifications You must be signed in to change notification settings

eldoy/easymongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

We also have Mongocore if you're looking for a full ORM.

Installation

gem install easymongo

or add to Gemfile.

Usage

# 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. We are the creators of CrowdfundHQ.

@authors: Vidar

About

Fast MongoDB client which makes using mongodb super easy

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages