mongo_db 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,16 +1,16 @@
1
- Mongo::Collection.class_eval do
2
- alias_method :save_with_ext, :save
3
- def save doc, opts = {}
4
- save_with_ext doc, reverse_merge_defaults(opts, :safe)
1
+ module Mongo::Ext::Collection
2
+ #
3
+ # CRUD
4
+ #
5
+ def save_with_ext doc, opts = {}
6
+ save_without_ext doc, reverse_merge_defaults(opts, :safe)
5
7
  end
6
8
 
7
- alias_method :insert_whth_ext, :insert
8
- def insert doc_or_docs, opts = {}
9
- insert_whth_ext doc_or_docs, reverse_merge_defaults(opts, :safe)
9
+ def insert_with_ext doc_or_docs, opts = {}
10
+ insert_without_ext doc_or_docs, reverse_merge_defaults(opts, :safe)
10
11
  end
11
12
 
12
- alias_method :update_whth_ext, :update
13
- def update selector, document, opts = {}
13
+ def update_with_ext selector, document, opts = {}
14
14
  # because :multi works only with $ operators, we need to check it
15
15
  opts = if document.keys.any?{|k| k =~ /^\$/}
16
16
  reverse_merge_defaults(opts, :safe, :multi)
@@ -18,14 +18,20 @@ Mongo::Collection.class_eval do
18
18
  reverse_merge_defaults(opts, :safe)
19
19
  end
20
20
 
21
- update_whth_ext selector, document, opts
21
+ update_without_ext selector, document, opts
22
22
  end
23
-
24
- alias_method :remove_with_ext, :remove
25
- def remove selector = {}, opts = {}
26
- remove_with_ext selector, reverse_merge_defaults(opts, :safe, :multi)
23
+
24
+ def remove_with_ext selector = {}, opts = {}
25
+ remove_without_ext selector, reverse_merge_defaults(opts, :safe, :multi)
26
+ end
27
+
28
+ def destroy *args
29
+ remove *args
27
30
  end
28
31
 
32
+ #
33
+ # Querying
34
+ #
29
35
  def first *args
30
36
  o = find_one *args
31
37
  ::Mongo::Ext::HashHelper.unmarshal o
@@ -55,8 +61,6 @@ Mongo::Collection.class_eval do
55
61
  end
56
62
  end
57
63
 
58
- alias_method :destroy, :remove
59
-
60
64
  protected
61
65
  def reverse_merge_defaults opts, *keys
62
66
  h = opts.clone
@@ -1,4 +1,4 @@
1
- Mongo::DB.class_eval do
1
+ module Mongo::Ext::DB
2
2
  protected
3
3
  def method_missing collection_name
4
4
  self.collection collection_name
@@ -0,0 +1,33 @@
1
+ require 'mongo_db/gems'
2
+
3
+ require 'mongo'
4
+
5
+ # namespace for extensions
6
+ class Mongo::Ext; end
7
+
8
+ %w(
9
+ database
10
+ collection
11
+ hash_helper
12
+ ).each{|f| require "mongo_db/driver/core/#{f}"}
13
+
14
+ # defaults
15
+ Mongo.class_eval do
16
+ class << self
17
+ def defaults; @defaults ||= {} end
18
+ attr_writer :defaults
19
+ end
20
+ end
21
+
22
+ # database
23
+ Mongo::DB.send :include, Mongo::Ext::DB
24
+
25
+ # collection
26
+ Mongo::Collection.class_eval do
27
+ include Mongo::Ext::Collection
28
+
29
+ %w(insert update remove save).each do |method|
30
+ alias_method "#{method}_without_ext", method
31
+ alias_method method, "#{method}_with_ext"
32
+ end
33
+ end
@@ -0,0 +1,43 @@
1
+ module Mongo::Ext::Collection
2
+ #
3
+ # first_by_id, special case
4
+ #
5
+ def first_by_id id
6
+ first _id: id
7
+ end
8
+ alias_method :by_id, :first_by_id
9
+
10
+ def first_by_id! id
11
+ first_by_id(id) || raise(Mongo::NotFound, "document with id #{id} not found!")
12
+ end
13
+ alias_method :by_id!, :first_by_id!
14
+
15
+ protected
16
+ #
17
+ # first_by_field, all_by_field
18
+ #
19
+ def method_missing clause, *a, &b
20
+ if clause =~ /^([a-z]_by_[a-z_])|(by_[a-z_])/
21
+ clause = clause.to_s
22
+
23
+ bang = clause =~ /!$/
24
+ clause = clause[0..-2] if bang
25
+
26
+ finder, field = if clause =~ /^by_/
27
+ ['first', clause.sub(/by_/, '')]
28
+ else
29
+ clause.split(/_by_/, 2)
30
+ end
31
+ finder = 'first' if finder == 'find'
32
+
33
+ raise "You can't use bang version with :#{finder}!" if bang and finder != 'first'
34
+
35
+ raise "invalid arguments for finder (#{a})!" unless a.size == 1
36
+ field_value = a.first
37
+
38
+ send(finder, field => field_value) || (bang && raise(Mongo::NotFound, "document with #{field}: #{field_value} not found!"))
39
+ else
40
+ super
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ require 'mongo_db/driver/core'
2
+
3
+ class Mongo::NotFound < StandardError; end
4
+
5
+ %w(
6
+ collection
7
+ ).each{|f| require "mongo_db/driver/more/#{f}"}
8
+
9
+ Mongo.defaults.merge! \
10
+ symbolize: true,
11
+ batch_size: 50,
12
+ multi: true,
13
+ safe: true
@@ -1,23 +1,2 @@
1
- require 'mongo_db/gems'
2
-
3
- require 'mongo'
4
-
5
- # namespace for extensions
6
- class Mongo::Ext; end
7
-
8
- # mongo extensions
9
- Mongo.class_eval do
10
- def self.defaults; @defaults ||= {} end
11
- defaults.merge! \
12
- symbolize: true,
13
- batch_size: 50,
14
- multi: true,
15
- safe: true
16
- end
17
-
18
- %w(
19
- support
20
- database
21
- collection
22
- hash_helper
23
- ).each{|f| require "mongo_db/driver/#{f}"}
1
+ require 'mongo_db/driver/core'
2
+ require 'mongo_db/driver/more'
@@ -1,3 +1,5 @@
1
+
2
+
1
3
  # Hash.class_eval do
2
4
  # unless defined_method? :subset
3
5
  # def subset *keys, &block
data/readme.md CHANGED
@@ -1,37 +1,54 @@
1
- Object Model & Ruby driver enhancements for MongoDB
1
+ Object Model & Ruby driver enhancements for MongoDB.
2
2
 
3
3
  # MongoDB driver enhancements
4
4
 
5
- - Makes alien API of mongo-ruby-driver friendly & handy.
5
+ MongoDB itself is very powerful, flexible and simple tool, but it's Ruby driver hides it behind complicated API.
6
+ This enhancements alter the Ruby-driver's API to be more simple and intuitive.
7
+
8
+ - Makes API of mongo-ruby-driver friendly & handy.
6
9
  - No extra abstraction or complexities introduced, all things are exactly the same as in MongoDB.
7
- - Simple migrations support.
10
+ - Simple migrations support (work in progress).
8
11
 
9
- Sample:
12
+ Note: By default it also adds a little magic and alters some default values of standard driver to be more useful, but You can omit it and require only the core stuff: use *requre 'mongo_db/driver/core'* instead of *requre 'mongo_db/driver'*
10
13
 
11
14
  ``` ruby
12
15
  require 'mongo_db/driver'
13
16
 
14
- # collection shortcuts
15
- db.some_collection
17
+ # connection & db
18
+ connection = Mongo::Connection.new
19
+ db = connection.db 'default_test'
16
20
 
17
- # save & update
18
- zeratul = {name: 'Zeratul'}
19
- db.heroes.save zeratul
21
+ # create
22
+ zeratul = {name: 'Zeratul', stats: {attack: 85, life: 300, shield: 100}}
23
+ tassadar = {name: 'Tassadar', stats: {attack: 0, life: 80, shield: 300}}
20
24
 
21
- # first & all
22
- db.heroes.first name: 'Zeratul' # => {name: 'Zeratul'}
25
+ db.units.save zeratul
26
+ db.units.save tassadar
23
27
 
24
- db.heroes.all name: 'Zeratul' # => [{name: 'Zeratul'}]
25
- db.heroes.all name: 'Zeratul' do |hero|
26
- hero # => {name: 'Zeratul'}
27
- end
28
+ # udate (we made error - mistakenly set Tassadar's attack as zero, let's fix it)
29
+ tassadar[:stats][:attack] = 20
30
+ db.units.save tassadar
28
31
 
29
- # each
30
- db.heroes.each name: 'Zeratul' do |hero|
31
- hero # => {name: 'Zeratul'}
32
+ # querying - first & all, there's also :each, the same as :all
33
+ db.units.first name: 'Zeratul' # => zeratul
34
+ db.units.all name: 'Zeratul' # => [zeratul]
35
+ db.units.all name: 'Zeratul' do |hero|
36
+ hero # => zeratul
32
37
  end
33
38
  ```
34
39
 
40
+ Optionall stuff:
41
+
42
+ ``` ruby
43
+ # simple finders (bang versions also availiable)
44
+ db.units.by_name 'Zeratul' # => zeratul
45
+ db.units.first_by_name 'Zeratul' # => zeratul
46
+ db.units.all_by_name 'Zeratul' # => [zeratul]
47
+ ```
48
+
49
+ More docs - there's no need for more docs, the whole point of this extension is to be small, intuitive, 100% compatible with official driver (at least should be), and require no extra knowledge.
50
+ So, please use standard Ruby driver documentation.
51
+
35
52
  # Object Model (work in progress)
36
53
 
37
54
  Model designed after the excellent "Domain-Driven Design" book by Eric Evans.
@@ -45,14 +62,21 @@ Model designed after the excellent "Domain-Driven Design" book by Eric Evans.
45
62
 
46
63
  # Installation & Usage
47
64
 
65
+ Installation:
66
+
48
67
  ``` bash
49
68
  gem install mongo_db
50
69
  ```
51
70
 
71
+ Usage:
72
+
52
73
  ``` ruby
53
74
  require 'mongo_db/driver'
54
75
  ```
55
76
 
56
77
  # License
57
78
 
58
- Copyright (c) Alexey Petrushin, http://petrush.in, released under the MIT license.
79
+ Copyright (c) Alexey Petrushin, http://petrush.in, released under the MIT license.
80
+
81
+ [mongo_mapper_ext]: https://github.com/alexeypetrushin/mongo_mapper_ext
82
+ [mongoid_misc]: https://github.com/alexeypetrushin/mongoid_misc
@@ -19,8 +19,8 @@ describe "Collection" do
19
19
  describe "symbolize" do
20
20
  it 'should always return symbolized hashes' do
21
21
  zeratul = {name: 'Zeratul'}
22
- db.heroes.save(zeratul).should be_mongo_id
23
- r = db.heroes.first(name: 'Zeratul')
22
+ db.units.save(zeratul).should be_mongo_id
23
+ r = db.units.first(name: 'Zeratul')
24
24
  r[:_id].should be_mongo_id
25
25
  r['_id'].should be_nil
26
26
  r[:name].should == 'Zeratul'
@@ -33,8 +33,8 @@ describe "Collection" do
33
33
  Mongo.defaults[:symbolize] = false
34
34
 
35
35
  zeratul = {name: 'Zeratul'}
36
- db.heroes.save(zeratul).should be_mongo_id
37
- r = db.heroes.first(name: 'Zeratul')
36
+ db.units.save(zeratul).should be_mongo_id
37
+ r = db.units.first(name: 'Zeratul')
38
38
  r[:_id].should be_nil
39
39
  r['_id'].should be_mongo_id
40
40
  r[:name].should be_nil
@@ -46,24 +46,24 @@ describe "Collection" do
46
46
  end
47
47
 
48
48
  it "first" do
49
- db.heroes.first.should be_nil
49
+ db.units.first.should be_nil
50
50
  zeratul = {name: 'Zeratul'}
51
- db.heroes.save(zeratul).should be_mongo_id
52
- db.heroes.first(name: 'Zeratul')[:name].should == 'Zeratul'
51
+ db.units.save(zeratul).should be_mongo_id
52
+ db.units.first(name: 'Zeratul')[:name].should == 'Zeratul'
53
53
  end
54
54
 
55
55
  it 'all' do
56
- db.heroes.all.should == []
56
+ db.units.all.should == []
57
57
 
58
58
  zeratul = {name: 'Zeratul'}
59
- db.heroes.save(zeratul).should be_mongo_id
59
+ db.units.save(zeratul).should be_mongo_id
60
60
 
61
- list = db.heroes.all(name: 'Zeratul')
61
+ list = db.units.all(name: 'Zeratul')
62
62
  list.size.should == 1
63
63
  list.first[:name].should == 'Zeratul'
64
64
 
65
65
  # with block
66
- list = []; db.heroes.all{|o| list << o}
66
+ list = []; db.units.all{|o| list << o}
67
67
  list.size.should == 1
68
68
  list.first[:name].should == 'Zeratul'
69
69
  end
@@ -10,28 +10,28 @@ describe "Hash CRUD" do
10
10
 
11
11
  it 'crud' do
12
12
  # read
13
- db.heroes.count.should == 0
14
- db.heroes.all.should == []
15
- db.heroes.first.should == nil
13
+ db.units.count.should == 0
14
+ db.units.all.should == []
15
+ db.units.first.should == nil
16
16
 
17
17
  # create
18
- db.heroes.save(@zeratul).should be_mongo_id
18
+ db.units.save(@zeratul).should be_mongo_id
19
19
  @zeratul[:_id].should be_mongo_id
20
20
 
21
21
  # read
22
- db.heroes.all.should == [@zeratul]
23
- db.heroes.count.should == 1
24
- db.heroes.first.should == @zeratul
22
+ db.units.all.should == [@zeratul]
23
+ db.units.count.should == 1
24
+ db.units.first.should == @zeratul
25
25
 
26
26
  # update
27
27
  @zeratul[:info] = 'Killer of Cerebrates'
28
- db.heroes.save @zeratul
29
- db.heroes.count.should == 1
30
- db.heroes.first(name: 'Zeratul')[:info].should == 'Killer of Cerebrates'
28
+ db.units.save @zeratul
29
+ db.units.count.should == 1
30
+ db.units.first(name: 'Zeratul')[:info].should == 'Killer of Cerebrates'
31
31
 
32
32
  # destroy
33
- db.heroes.destroy @zeratul
34
- db.heroes.count.should == 0
33
+ db.units.destroy @zeratul
34
+ db.units.count.should == 0
35
35
  end
36
36
  end
37
37
 
@@ -0,0 +1,26 @@
1
+ before do
2
+ @zeratul = {name: 'Zeratul', stats: {attack: 85, life: 300, shield: 100}}
3
+ @tassadar = {name: 'Tassadar', stats: {attack: 20, life: 80, shield: 300}}
4
+
5
+ db.units.save @zeratul
6
+ db.units.save @tassadar
7
+ end
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+ it "selector" do
19
+ db.units.select{|u|
20
+ u.stats.life < 100
21
+ u.name.exist
22
+ u.name.in
23
+ }.first.should == @tassadar
24
+
25
+ db.units.select{|u| }
26
+ end
@@ -0,0 +1,51 @@
1
+ require 'driver/spec_helper'
2
+
3
+ describe "Querying" do
4
+ with_mongo
5
+
6
+ before do
7
+ @jim = {name: 'Jim'}
8
+ @units = db.units
9
+ end
10
+
11
+ it "find, first, by" do
12
+ @units.first_by_name('Jim').should be_nil
13
+ -> {@units.first_by_name!('Jim')}.should raise_error(Mongo::NotFound)
14
+ @units.by_name('Jim').should be_nil
15
+ -> {@units.by_name!('Jim')}.should raise_error(Mongo::NotFound)
16
+ @units.first_by_name('Jim').should be_nil
17
+ -> {@units.first_by_name!('Jim')}.should raise_error(Mongo::NotFound)
18
+
19
+ @units.save @jim
20
+
21
+ @units.first_by_name('Jim').should == @jim
22
+ @units.first_by_name!('Jim').should == @jim
23
+ @units.by_name('Jim').should == @jim
24
+ @units.by_name!('Jim').should == @jim
25
+ @units.first_by_name('Jim').should == @jim
26
+ @units.first_by_name!('Jim').should == @jim
27
+ end
28
+
29
+ it "all" do
30
+ @units.all_by_name('Jim').should == []
31
+ @units.save @jim
32
+ @units.all_by_name('Jim').should == [@jim]
33
+ end
34
+
35
+ it "should allow to use bang version only with :first" do
36
+ -> {@units.all_by_name!('Jim')}.should raise_error(/can't use bang/)
37
+ end
38
+
39
+ it "by_id (special case)" do
40
+ @units.method(:by_id).should == @units.method(:first_by_id)
41
+ @units.method(:by_id!).should == @units.method(:first_by_id!)
42
+
43
+ @units.by_id('4de81858cf26bde569000009').should be_nil
44
+ -> {@units.by_id!('4de81858cf26bde569000009')}.should raise_error(Mongo::NotFound)
45
+
46
+ @units.save @jim
47
+
48
+ @units.by_id(@jim[:_id]).should == @jim
49
+ @units.by_id!(@jim[:_id]).should == @jim
50
+ end
51
+ end
@@ -1,6 +1,6 @@
1
1
  require 'mongo_db/driver'
2
- require 'ruby_ext'
3
2
 
3
+ require 'ruby_ext'
4
4
  require 'rspec_ext'
5
5
  require 'mongo_db/driver/spec'
6
6
 
@@ -0,0 +1,45 @@
1
+ require 'driver/spec_helper'
2
+
3
+ describe "Example" do
4
+ with_mongo
5
+
6
+ defaults = nil
7
+ before(:all){defaults = Mongo.defaults.clone}
8
+ after(:all){Mongo.defaults = defaults}
9
+
10
+ it "core" do
11
+ require 'mongo_db/driver'
12
+
13
+ # connection & db
14
+ connection = Mongo::Connection.new
15
+ db = connection.db 'default_test'
16
+
17
+ # collection shortcuts
18
+ db.some_collection
19
+
20
+ # create
21
+ zeratul = {name: 'Zeratul', stats: {attack: 85, life: 300, shield: 100}}
22
+ tassadar = {name: 'Tassadar', stats: {attack: 0, life: 80, shield: 300}}
23
+
24
+ db.units.save zeratul
25
+ db.units.save tassadar
26
+
27
+ # udate (we made error - mistakenly set Tassadar's attack as zero, let's fix it)
28
+ tassadar[:stats][:attack] = 20
29
+ db.units.save tassadar
30
+
31
+ # querying first & all, there's also :each, the same as :all
32
+ db.units.first name: 'Zeratul' # => zeratul
33
+ db.units.all name: 'Zeratul' # => [zeratul]
34
+ db.units.all name: 'Zeratul' do |hero|
35
+ hero # => zeratul
36
+ end
37
+ end
38
+
39
+ it "optional" do
40
+ # simple finders (bang versions also availiable)
41
+ db.units.by_name 'Zeratul' # => zeratul
42
+ db.units.first_by_name 'Zeratul' # => zeratul
43
+ db.units.all_by_name 'Zeratul' # => [zeratul]
44
+ end
45
+ end
@@ -8,7 +8,7 @@ describe "Model CRUD" do
8
8
  before do
9
9
  class Person
10
10
  inherit Mongo::Model
11
- collection{db.heroes}
11
+ collection{db.units}
12
12
 
13
13
  def initialize name, info; @name, @info = name, info end
14
14
  attr_accessor :name, :info
@@ -1,29 +1,29 @@
1
1
  shared_examples_for 'object CRUD' do
2
2
  it 'crud' do
3
3
  # read
4
- db.heroes.count.should == 0
5
- db.heroes.all.should == []
6
- db.heroes.first.should == nil
4
+ db.units.count.should == 0
5
+ db.units.all.should == []
6
+ db.units.first.should == nil
7
7
 
8
8
  # create
9
- db.heroes.save(@zeratul).should be_true
9
+ db.units.save(@zeratul).should be_true
10
10
  @zeratul.instance_variable_get(:@_id).should be_present
11
11
 
12
12
  # read
13
- db.heroes.count.should == 1
14
- db.heroes.all.should == [@zeratul]
15
- db.heroes.first.should == @zeratul
16
- db.heroes.first.object_id.should_not == @zeratul.object_id
13
+ db.units.count.should == 1
14
+ db.units.all.should == [@zeratul]
15
+ db.units.first.should == @zeratul
16
+ db.units.first.object_id.should_not == @zeratul.object_id
17
17
 
18
18
  # update
19
19
  @zeratul.info = 'Killer of Cerebrates'
20
- db.heroes.save(@zeratul).should be_true
21
- db.heroes.count.should == 1
22
- db.heroes.first(name: 'Zeratul').info.should == 'Killer of Cerebrates'
20
+ db.units.save(@zeratul).should be_true
21
+ db.units.count.should == 1
22
+ db.units.first(name: 'Zeratul').info.should == 'Killer of Cerebrates'
23
23
 
24
24
  # destroy
25
- db.heroes.destroy(@zeratul).should be_true
26
- db.heroes.count.should == 0
25
+ db.units.destroy(@zeratul).should be_true
26
+ db.units.count.should == 0
27
27
  end
28
28
  end
29
29
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-12 00:00:00.000000000Z
12
+ date: 2011-08-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo
16
- requirement: &2845070 !ruby/object:Gem::Requirement
16
+ requirement: &2844700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2845070
24
+ version_requirements: *2844700
25
25
  description:
26
26
  email:
27
27
  executables: []
@@ -30,20 +30,24 @@ extra_rdoc_files: []
30
30
  files:
31
31
  - Rakefile
32
32
  - readme.md
33
- - lib/mongo_db/driver/collection.rb
34
- - lib/mongo_db/driver/database.rb
35
- - lib/mongo_db/driver/hash_helper.rb
33
+ - lib/mongo_db/driver/core/collection.rb
34
+ - lib/mongo_db/driver/core/database.rb
35
+ - lib/mongo_db/driver/core/hash_helper.rb
36
+ - lib/mongo_db/driver/core.rb
37
+ - lib/mongo_db/driver/more/collection.rb
38
+ - lib/mongo_db/driver/more.rb
36
39
  - lib/mongo_db/driver/spec.rb
37
- - lib/mongo_db/driver/support.rb
38
40
  - lib/mongo_db/driver.rb
39
41
  - lib/mongo_db/gems.rb
40
42
  - lib/mongo_db/model.rb
41
- - spec/driver/collection_spec.rb
42
- - spec/driver/crud_spec.rb
43
- - spec/driver/database_spec.rb
44
- - spec/driver/example_spec.rb
45
- - spec/driver/query_spec.rb
43
+ - lib/mongo_db/support.rb
44
+ - spec/driver/core/collection_spec.rb
45
+ - spec/driver/core/crud_spec.rb
46
+ - spec/driver/core/database_spec.rb
47
+ - spec/driver/more/advanced_finders.rb
48
+ - spec/driver/more/simple_finders_spec.rb
46
49
  - spec/driver/spec_helper.rb
50
+ - spec/driver_example_spec.rb
47
51
  - spec/migration/migration_spec.rb
48
52
  - spec/model/model/crud.rb
49
53
  - spec/model/model/query.rb
@@ -1,29 +0,0 @@
1
- require 'driver/spec_helper'
2
-
3
- describe "Example" do
4
- with_mongo
5
-
6
- it "database & collection" do
7
- require 'mongo_db/driver'
8
-
9
- # collection shortcuts
10
- db.some_collection
11
-
12
- # save & update
13
- zeratul = {name: 'Zeratul'}
14
- db.heroes.save zeratul
15
-
16
- # first & all
17
- db.heroes.first name: 'Zeratul' # => {name: 'Zeratul'}
18
-
19
- db.heroes.all name: 'Zeratul' # => [{name: 'Zeratul'}]
20
- db.heroes.all name: 'Zeratul' do |hero|
21
- hero # => {name: 'Zeratul'}
22
- end
23
-
24
- # each
25
- db.heroes.each name: 'Zeratul' do |hero|
26
- hero # => {name: 'Zeratul'}
27
- end
28
- end
29
- end
@@ -1,27 +0,0 @@
1
- # require 'driver/spec_helper'
2
- #
3
- # describe "Querying" do
4
- # with_mongo
5
- #
6
- # it "database & collection" do
7
- # # collection shortcuts
8
- # db.some_collection
9
- #
10
- # # save & update
11
- # zeratul = {name: 'Zeratul'}
12
- # db.heroes.save zeratul
13
- #
14
- # # first & all
15
- # db.heroes.first name: 'Zeratul' # => {name: 'Zeratul'}
16
- #
17
- # db.heroes.all name: 'Zeratul' # => [{name: 'Zeratul'}]
18
- # db.heroes.all name: 'Zeratul' do |hero|
19
- # hero # => {name: 'Zeratul'}
20
- # end
21
- #
22
- # # each
23
- # db.heroes.each name: 'Zeratul' do |hero|
24
- # hero # => {name: 'Zeratul'}
25
- # end
26
- # end
27
- # end