mongous 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +6 -3
- data/README.ja.adoc +6 -3
- data/lib/mongous/base.rb +12 -2
- data/lib/mongous/extention.rb +4 -0
- data/lib/mongous/filter.rb +57 -14
- data/lib/mongous/version.rb +1 -1
- data/sample/connect_auto_0.rb +1 -1
- data/sample/declare_compact_1.rb +0 -2
- data/sample/declare_compact_2.rb +38 -0
- data/sample/declare_label_1.rb +0 -2
- data/sample/declare_ndex_1.rb +0 -2
- data/sample/declare_ndex_2.rb +0 -2
- data/sample/declare_strict_1.rb +0 -2
- data/sample/declare_strict_2.rb +0 -2
- data/sample/multi_collection_1.rb +0 -2
- data/sample/multi_collection_2.rb +0 -2
- data/sample/multi_collection_3.rb +6 -8
- data/sample/query_basic_1.rb +8 -2
- data/sample/query_basic_2.rb +8 -2
- data/sample/query_basic_3.rb +0 -2
- data/sample/query_basic_4.rb +0 -2
- data/sample/query_basic_5.rb +0 -2
- data/sample/query_basic_6.rb +56 -0
- data/sample/query_detail_1.rb +0 -2
- data/sample/query_detail_2.rb +0 -2
- data/sample/query_detail_3.rb +0 -2
- data/sample/query_filter_1.rb +0 -2
- data/sample/query_filter_2.rb +0 -2
- data/sample/query_find_1.rb +6 -5
- data/sample/query_select_1.rb +8 -5
- data/sample/query_skip_limit_1.rb +17 -16
- data/sample/query_skip_limit_2.rb +19 -10
- data/sample/query_sort_1.rb +43 -0
- data/sample/save_basic_1.rb +1 -5
- data/sample/save_basic_2.rb +1 -5
- data/sample/save_basic_3.rb +1 -5
- data/sample/save_detail_1.rb +0 -2
- data/sample/save_detail_2.rb +0 -2
- data/sample/save_detail_3.rb +0 -2
- data/sample/save_verify_1.rb +0 -2
- data/sample/save_verify_2.rb +0 -2
- data/sample/save_verify_3.rb +0 -2
- data/sample/save_verify_4.rb +0 -2
- data/sample/save_verify_5.rb +0 -2
- data/sample/save_verify_6.rb +0 -2
- data/sample/save_verify_7.rb +0 -2
- data/sample/update_basic_1.rb +1 -5
- data/sample/zap_basic_1.rb +1 -5
- data/sample/zap_basic_2.rb +2 -6
- data/sample/zap_basic_3.rb +1 -5
- data/sample/zbenchmark_search_1.rb +19 -15
- data/sample/zbenchmark_search_2.rb +19 -15
- data/sample/zbenchmark_search_3.rb +25 -27
- metadata +5 -3
- data/sample/query_sort_order_1.rb +0 -46
data/sample/query_basic_2.rb
CHANGED
@@ -1,21 +1,27 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.connect!
|
5
|
-
|
6
4
|
class Book
|
7
5
|
include Mongous::Document
|
8
6
|
end
|
9
7
|
|
8
|
+
p "book = Book.where( title: /title/ ).first"
|
10
9
|
p book = Book.where( title: /title/ ).first
|
11
10
|
puts
|
12
11
|
|
12
|
+
p "book = Book.where( title: /title/ ).last"
|
13
|
+
p book = Book.where( title: /title/ ).last
|
14
|
+
puts
|
15
|
+
|
16
|
+
p "count = Book.where( title: /title/ ).count"
|
13
17
|
p count = Book.where( title: /title/ ).count
|
14
18
|
puts
|
15
19
|
|
20
|
+
p "books = Book.where( title: /title/ ).all"
|
16
21
|
pp books = Book.where( title: /title/ ).all
|
17
22
|
puts
|
18
23
|
|
24
|
+
p "Book.where( title: /title/ ).each do |book|"
|
19
25
|
Book.where( title: /title/ ).each do |book|
|
20
26
|
p book
|
21
27
|
end
|
data/sample/query_basic_3.rb
CHANGED
data/sample/query_basic_4.rb
CHANGED
data/sample/query_basic_5.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
# use new syntax from ruby 2.7
|
3
|
+
|
4
|
+
require "mongous"
|
5
|
+
|
6
|
+
Mongous.document! :Item
|
7
|
+
|
8
|
+
(0...10).each do |n|
|
9
|
+
unless Item.where( n: n ).first
|
10
|
+
Item.create( n: n, tag: [0x40 + n].pack("C") )
|
11
|
+
end
|
12
|
+
end
|
13
|
+
puts
|
14
|
+
|
15
|
+
p "Item.where( n: (2..5) ).select( _id: 0 ).each do |item|"
|
16
|
+
Item.where( n: (2..5) ).select( _id: 0 ).each do |item|
|
17
|
+
p item
|
18
|
+
end
|
19
|
+
puts
|
20
|
+
|
21
|
+
p "Item.where( n: (2...5) ).select( _id: 0 ).each do |item|"
|
22
|
+
Item.where( n: (2...5) ).select( _id: 0 ).each do |item|
|
23
|
+
p item
|
24
|
+
end
|
25
|
+
puts
|
26
|
+
|
27
|
+
p "Item.where( n: (..5) ).select( _id: 0 ).each do |item|"
|
28
|
+
Item.where( n: (..5) ).select( _id: 0 ).each do |item|
|
29
|
+
p item
|
30
|
+
end
|
31
|
+
puts
|
32
|
+
|
33
|
+
p "Item.where( n: (...5) ).select( _id: 0 ).each do |item|"
|
34
|
+
Item.where( n: (...5) ).select( _id: 0 ).each do |item|
|
35
|
+
p item
|
36
|
+
end
|
37
|
+
puts
|
38
|
+
|
39
|
+
p "Item.where( n: (2..) ).select( _id: 0 ).each do |item|"
|
40
|
+
Item.where( n: (2..) ).select( _id: 0 ).each do |item|
|
41
|
+
p item
|
42
|
+
end
|
43
|
+
puts
|
44
|
+
|
45
|
+
p "Item.not( n: (..2) ).select( _id: 0 ).each do |item|"
|
46
|
+
Item.not( n: (..2) ).select( _id: 0 ).each do |item|
|
47
|
+
p item
|
48
|
+
end
|
49
|
+
puts
|
50
|
+
|
51
|
+
p "Item.select( _id: 0 ).not( n: (..2) ).each do |item|"
|
52
|
+
Item.select( _id: 0 ).not( n: (..2) ).each do |item|
|
53
|
+
p item
|
54
|
+
end
|
55
|
+
puts
|
56
|
+
|
data/sample/query_detail_1.rb
CHANGED
data/sample/query_detail_2.rb
CHANGED
data/sample/query_detail_3.rb
CHANGED
data/sample/query_filter_1.rb
CHANGED
data/sample/query_filter_2.rb
CHANGED
data/sample/query_find_1.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.
|
5
|
-
|
6
|
-
class Book
|
7
|
-
include Mongous::Document
|
8
|
-
end
|
4
|
+
Mongous.document! :Book
|
9
5
|
|
6
|
+
p "book = Book.find.first"
|
10
7
|
p book = Book.find.first
|
11
8
|
puts
|
12
9
|
|
10
|
+
p "Book.find.each do |book|"
|
13
11
|
Book.find.each do |book|
|
14
12
|
p book
|
15
13
|
end
|
16
14
|
puts
|
17
15
|
|
16
|
+
p "Book.find( title: /title/ ).each do |book|"
|
18
17
|
Book.find( title: /title/ ).each do |book|
|
19
18
|
p book
|
20
19
|
end
|
21
20
|
puts
|
22
21
|
|
22
|
+
p "Book.find( {}, { projection: {_id: 0} } ).each do |book|"
|
23
23
|
Book.find( {}, { projection: {_id: 0} } ).each do |book|
|
24
24
|
p book
|
25
25
|
end
|
26
26
|
puts
|
27
27
|
|
28
|
+
p "Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|"
|
28
29
|
Book.find( {title: /title/}, { projection: {_id: 0} } ).each do |book|
|
29
30
|
p book
|
30
31
|
end
|
data/sample/query_select_1.rb
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.
|
5
|
-
|
6
|
-
class Label
|
7
|
-
include Mongous::Document
|
8
|
-
end
|
4
|
+
Mongous.document! :Label
|
9
5
|
|
10
6
|
(0...10).each do |n|
|
11
7
|
unless Label.where( n: n ).first
|
@@ -14,36 +10,43 @@ end
|
|
14
10
|
end
|
15
11
|
puts
|
16
12
|
|
13
|
+
p "Label.each do |label|"
|
17
14
|
Label.each do |label|
|
18
15
|
p label
|
19
16
|
end
|
20
17
|
puts
|
21
18
|
|
19
|
+
p "Label.select( tag: 1 ).each do |label|"
|
22
20
|
Label.select( tag: 1 ).each do |label|
|
23
21
|
p label
|
24
22
|
end
|
25
23
|
puts
|
26
24
|
|
25
|
+
p "Label.select( :tag ).each do |label|"
|
27
26
|
Label.select( :tag ).each do |label|
|
28
27
|
p label
|
29
28
|
end
|
30
29
|
puts
|
31
30
|
|
31
|
+
p "Label.select( _id: 0, n: 1 ).each do |label|"
|
32
32
|
Label.select( _id: 0, n: 1 ).each do |label|
|
33
33
|
p label
|
34
34
|
end
|
35
35
|
puts
|
36
36
|
|
37
|
+
p "Label.select( n: 1, tag: 1 ).each do |label|"
|
37
38
|
Label.select( n: 1, tag: 1 ).each do |label|
|
38
39
|
p label
|
39
40
|
end
|
40
41
|
puts
|
41
42
|
|
43
|
+
p "Label.select( :n, :tag ).each do |label|"
|
42
44
|
Label.select( :n, :tag ).each do |label|
|
43
45
|
p label
|
44
46
|
end
|
45
47
|
puts
|
46
48
|
|
49
|
+
p "Label.select( _id: 0, n: 1, tag: 1 ).where( n: [0,2,4,6,8] ).each do |label|"
|
47
50
|
Label.select( _id: 0, n: 1, tag: 1 ).where( n: [0,2,4,6,8] ).each do |label|
|
48
51
|
p label
|
49
52
|
end
|
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.
|
5
|
-
|
6
|
-
class Item
|
7
|
-
include Mongous::Document
|
8
|
-
end
|
4
|
+
Mongous.document! :Item
|
9
5
|
|
10
6
|
(0...10).each do |n|
|
11
7
|
unless Item.where( n: n ).first
|
@@ -14,33 +10,38 @@ end
|
|
14
10
|
end
|
15
11
|
puts
|
16
12
|
|
13
|
+
p "count = Item.count"
|
17
14
|
p count = Item.count
|
18
15
|
puts
|
19
16
|
|
20
|
-
p count = Item.
|
17
|
+
p "count = Item[0..4].count"
|
18
|
+
p count = Item[0..4].count
|
21
19
|
puts
|
22
20
|
|
23
|
-
p count = Item
|
21
|
+
p "count = Item[0...4].count"
|
22
|
+
p count = Item[0...4].count
|
24
23
|
puts
|
25
24
|
|
26
|
-
p count = Item
|
25
|
+
p "count = Item[0, 4].count"
|
26
|
+
p count = Item[0, 4].count
|
27
27
|
puts
|
28
28
|
|
29
|
-
p count = Item
|
29
|
+
p "count = Item[5, 5].count"
|
30
|
+
p count = Item[5, 5].count
|
30
31
|
puts
|
31
32
|
|
32
|
-
p
|
33
|
+
p "books = Item[0, 2].all"
|
34
|
+
pp books = Item[0, 2].all
|
33
35
|
puts
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
filter = Item.where
|
39
|
-
filter[0, 4].each do |item|
|
37
|
+
p "Item[0, 4].each do |item|"
|
38
|
+
Item[0, 4].each do |item|
|
40
39
|
p item
|
41
40
|
end
|
42
41
|
puts
|
43
|
-
|
42
|
+
|
43
|
+
p "Item[4, 4].each do |item|"
|
44
|
+
Item[4, 4].each do |item|
|
44
45
|
p item
|
45
46
|
end
|
46
47
|
puts
|
@@ -1,11 +1,7 @@
|
|
1
1
|
|
2
2
|
require "mongous"
|
3
3
|
|
4
|
-
Mongous.
|
5
|
-
|
6
|
-
class Item
|
7
|
-
include Mongous::Document
|
8
|
-
end
|
4
|
+
Mongous.document! :Item
|
9
5
|
|
10
6
|
(0...10).each do |n|
|
11
7
|
unless Item.where( n: n ).first
|
@@ -14,35 +10,48 @@ end
|
|
14
10
|
end
|
15
11
|
puts
|
16
12
|
|
13
|
+
p "Item.each do |item|"
|
17
14
|
Item.each do |item|
|
18
15
|
p item
|
19
16
|
end
|
20
17
|
puts
|
21
18
|
|
19
|
+
#Item.find.skip(2).limit(1).each do |item| p item; end; puts
|
20
|
+
p "Item[2].each do |item|"
|
21
|
+
Item[2].each do |item|
|
22
|
+
p item
|
23
|
+
end
|
24
|
+
puts
|
25
|
+
|
22
26
|
#Item.find.skip(2).each do |item| p item; end; puts
|
23
|
-
Item
|
27
|
+
p "Item[2, 0].each do |item|"
|
28
|
+
Item[2, 0].each do |item|
|
24
29
|
p item
|
25
30
|
end
|
26
31
|
puts
|
27
32
|
|
28
33
|
#Item.find.limit(3).each do |item| p item; end; puts
|
29
|
-
Item
|
34
|
+
p "Item[0, 3].each do |item|"
|
35
|
+
Item[0, 3].each do |item|
|
30
36
|
p item
|
31
37
|
end
|
32
38
|
puts
|
33
39
|
|
34
40
|
#Item.find.skip(4).limit(5).each do |item| p item; end; puts
|
35
|
-
Item
|
41
|
+
p "Item[4, 5].each do |item|"
|
42
|
+
Item[4, 5].each do |item|
|
36
43
|
p item
|
37
44
|
end
|
38
45
|
puts
|
39
46
|
|
40
|
-
Item
|
47
|
+
p "Item[4..8].each do |item|"
|
48
|
+
Item[4..8].each do |item|
|
41
49
|
p item
|
42
50
|
end
|
43
51
|
puts
|
44
52
|
|
45
|
-
Item
|
53
|
+
p "Item[4...8].each do |item|"
|
54
|
+
Item[4...8].each do |item|
|
46
55
|
p item
|
47
56
|
end
|
48
57
|
puts
|
@@ -0,0 +1,43 @@
|
|
1
|
+
|
2
|
+
require "mongous"
|
3
|
+
|
4
|
+
Mongous.document! :Mash
|
5
|
+
|
6
|
+
(0...10).each do |n|
|
7
|
+
unless Mash.where( n: n ).first
|
8
|
+
r = rand
|
9
|
+
Mash.create( n: n, r: r )
|
10
|
+
end
|
11
|
+
end
|
12
|
+
puts
|
13
|
+
|
14
|
+
p "Mash.each do |mash|"
|
15
|
+
Mash.each do |mash|
|
16
|
+
p mash
|
17
|
+
end
|
18
|
+
puts
|
19
|
+
|
20
|
+
p "Mash.sort(r: 1).each do |mash|"
|
21
|
+
Mash.sort(r: 1).each do |mash|
|
22
|
+
p mash
|
23
|
+
end
|
24
|
+
puts
|
25
|
+
|
26
|
+
p "Mash.sort(r: -1).each do |mash|"
|
27
|
+
Mash.sort(r: -1).each do |mash|
|
28
|
+
p mash
|
29
|
+
end
|
30
|
+
puts
|
31
|
+
|
32
|
+
p "Mash.where( n: (3...8) ).sort(r: -1).each do |mash|"
|
33
|
+
Mash.where( n: (3...8) ).sort(r: -1).each do |mash|
|
34
|
+
p mash
|
35
|
+
end
|
36
|
+
puts
|
37
|
+
|
38
|
+
p "Mash.where( n: [0,2,4,6,8] ).sort(r: -1).each do |mash|"
|
39
|
+
Mash.where( n: [0,2,4,6,8] ).sort(r: -1).each do |mash|
|
40
|
+
p mash
|
41
|
+
end
|
42
|
+
puts
|
43
|
+
|