mongo 0.18.2 → 0.18.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +37 -28
- data/Rakefile +19 -0
- data/bin/objectid_benchmark.rb +23 -0
- data/examples/admin.rb +7 -6
- data/examples/capped.rb +3 -4
- data/examples/cursor.rb +4 -3
- data/examples/gridfs.rb +3 -2
- data/examples/index_test.rb +10 -9
- data/examples/info.rb +3 -2
- data/examples/queries.rb +3 -2
- data/examples/simple.rb +3 -2
- data/examples/strict.rb +2 -1
- data/examples/types.rb +4 -3
- data/lib/mongo.rb +29 -12
- data/lib/mongo/admin.rb +17 -2
- data/lib/mongo/collection.rb +230 -169
- data/lib/mongo/connection.rb +136 -91
- data/lib/mongo/cursor.rb +68 -40
- data/lib/mongo/db.rb +247 -123
- data/lib/mongo/{errors.rb → exceptions.rb} +6 -5
- data/lib/mongo/gridfs.rb +6 -0
- data/lib/mongo/gridfs/grid_store.rb +142 -94
- data/lib/mongo/types/binary.rb +11 -1
- data/lib/mongo/types/code.rb +6 -1
- data/lib/mongo/types/dbref.rb +7 -2
- data/lib/mongo/types/min_max_keys.rb +58 -0
- data/lib/mongo/types/objectid.rb +76 -20
- data/lib/mongo/types/regexp_of_holding.rb +5 -0
- data/lib/mongo/util/bson_ruby.rb +36 -2
- data/lib/mongo/util/byte_buffer.rb +18 -2
- data/lib/mongo/util/conversions.rb +6 -5
- data/lib/mongo/util/ordered_hash.rb +3 -1
- data/lib/mongo/util/support.rb +3 -0
- data/lib/mongo/util/xml_to_ruby.rb +7 -0
- data/test/test_bson.rb +48 -0
- data/test/test_collection.rb +13 -0
- data/test/test_connection.rb +35 -0
- data/test/test_conversions.rb +1 -1
- data/test/test_cursor.rb +37 -5
- data/test/test_db.rb +51 -2
- data/test/test_db_api.rb +4 -7
- data/test/test_grid_store.rb +10 -0
- data/test/test_objectid.rb +16 -2
- data/test/test_ordered_hash.rb +14 -0
- data/test/threading/test_threading_large_pool.rb +4 -4
- data/test/unit/db_test.rb +43 -0
- metadata +5 -7
- data/examples/benchmarks.rb +0 -42
- data/examples/blog.rb +0 -76
- data/lib/mongo/constants.rb +0 -15
- data/test/mongo-qa/_common.rb +0 -8
data/examples/benchmarks.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
require "benchmark"
|
2
|
-
|
3
|
-
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
4
|
-
require 'mongo'
|
5
|
-
|
6
|
-
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
7
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::Connection::DEFAULT_PORT
|
8
|
-
|
9
|
-
puts "Connecting to #{host}:#{port}"
|
10
|
-
db = Mongo::Connection.new(host, port).db('ruby-mongo-examples')
|
11
|
-
coll = db.collection('test')
|
12
|
-
coll.clear
|
13
|
-
|
14
|
-
OBJS_COUNT = 100
|
15
|
-
TEST_COUNT = 100
|
16
|
-
|
17
|
-
puts "Generating benchmark data"
|
18
|
-
msgs = %w{hola hello aloha ciao}
|
19
|
-
arr = (0..OBJS_COUNT).collect {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }}
|
20
|
-
|
21
|
-
puts "Running benchmark"
|
22
|
-
Benchmark.bmbm do |results|
|
23
|
-
results.report("single object inserts: ") {
|
24
|
-
TEST_COUNT.times {
|
25
|
-
coll.clear
|
26
|
-
arr.each {|x| coll.insert(x)}
|
27
|
-
}
|
28
|
-
}
|
29
|
-
results.report("multiple object insert: ") {
|
30
|
-
TEST_COUNT.times {
|
31
|
-
coll.clear
|
32
|
-
coll.insert(arr)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
results.report("find_one: ") {
|
36
|
-
TEST_COUNT.times {
|
37
|
-
coll.find_one(:number => 0)
|
38
|
-
}
|
39
|
-
}
|
40
|
-
end
|
41
|
-
|
42
|
-
coll.clear
|
data/examples/blog.rb
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
|
3
|
-
class Exception
|
4
|
-
def errmsg
|
5
|
-
"%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
10
|
-
require 'mongo'
|
11
|
-
|
12
|
-
include Mongo
|
13
|
-
|
14
|
-
host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
15
|
-
port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
|
16
|
-
|
17
|
-
puts ">> Connecting to #{host}:#{port}"
|
18
|
-
DB = Connection.new(host, port).db('ruby-mongo-blog')
|
19
|
-
|
20
|
-
LINE_SIZE = 120
|
21
|
-
puts "=" * LINE_SIZE
|
22
|
-
puts "Adding authors"
|
23
|
-
authors = DB.collection "authors"
|
24
|
-
authors.clear
|
25
|
-
authors.create_index "meta", '_id' => 1, 'name' => 1, 'age' => 1
|
26
|
-
puts "-" * LINE_SIZE
|
27
|
-
shaksp = authors << { :name => "William Shakespeare", :email => "william@shakespeare.com", :age => 587 }
|
28
|
-
puts "shaksp : #{shaksp.inspect}"
|
29
|
-
borges = authors << { :name => "Jorge Luis Borges", :email => "jorge@borges.com", :age => 123 }
|
30
|
-
puts "borges : #{borges.inspect}"
|
31
|
-
puts "-" * LINE_SIZE
|
32
|
-
puts "authors ordered by age ascending"
|
33
|
-
puts "-" * LINE_SIZE
|
34
|
-
authors.find({}, :sort => [{'age' => 1}]).each {|x| puts "%-25.25s : %-25.25s : %3i" % [x['name'], x['email'], x['age']]}
|
35
|
-
|
36
|
-
puts "=" * LINE_SIZE
|
37
|
-
puts "Adding users"
|
38
|
-
users = DB.collection "users"
|
39
|
-
users.clear
|
40
|
-
# users.create_index "meta", :_id => 1, :login => 1, :name => 1
|
41
|
-
puts "-" * LINE_SIZE
|
42
|
-
jdoe = users << { :login => "jdoe", :name => "John Doe", :email => "john@doe.com" }
|
43
|
-
puts "jdoe : #{jdoe.inspect}"
|
44
|
-
lsmt = users << { :login => "lsmith", :name => "Lucy Smith", :email => "lucy@smith.com" }
|
45
|
-
puts "lsmt : #{lsmt.inspect}"
|
46
|
-
puts "-" * LINE_SIZE
|
47
|
-
puts "users ordered by login ascending"
|
48
|
-
puts "-" * LINE_SIZE
|
49
|
-
users.find({}, :sort => [{'login' => 1}]).each {|x| puts "%-10.10s : %-25.25s : %-25.25s" % [x['login'], x['name'], x['email']]}
|
50
|
-
|
51
|
-
puts "=" * LINE_SIZE
|
52
|
-
puts "Adding articles"
|
53
|
-
articles = DB.collection "articles"
|
54
|
-
articles.clear
|
55
|
-
# articles.create_index "meta", :_id => 1, :author_id => 1, :title => 1
|
56
|
-
puts "-" * LINE_SIZE
|
57
|
-
begin
|
58
|
-
art1 = articles << { :title => "Caminando por Buenos Aires", :body => "Las callecitas de Buenos Aires tienen ese no se que...", :author_id => borges["_id"].to_s }
|
59
|
-
puts "art1 : #{art1.inspect}"
|
60
|
-
rescue => e
|
61
|
-
puts "Error: #{e.errmsg}"
|
62
|
-
end
|
63
|
-
begin
|
64
|
-
art2 = articles << { :title => "I must have seen thy face before", :body => "Thine eyes call me in a new way", :author_id => shaksp["_id"].to_s, :comments => [ { :user_id => jdoe["_id"].to_s, :body => "great article!" } ] }
|
65
|
-
puts "art2 : #{art2.inspect}"
|
66
|
-
rescue => e
|
67
|
-
puts "Error: #{e.errmsg}"
|
68
|
-
end
|
69
|
-
puts "-" * LINE_SIZE
|
70
|
-
puts "articles ordered by title ascending"
|
71
|
-
puts "-" * LINE_SIZE
|
72
|
-
articles.find({}, :sort => [{'title' => 1}]).each {|x| puts "%-25.25s : %-25.25s" % [x['title'], x['author_id']]}
|
73
|
-
|
74
|
-
puts ">> Closing connection"
|
75
|
-
DB.close
|
76
|
-
puts "closed"
|
data/lib/mongo/constants.rb
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
module Mongo
|
2
|
-
module Constants
|
3
|
-
OP_REPLY = 1
|
4
|
-
OP_MSG = 1000
|
5
|
-
OP_UPDATE = 2001
|
6
|
-
OP_INSERT = 2002
|
7
|
-
OP_QUERY = 2004
|
8
|
-
OP_GET_MORE = 2005
|
9
|
-
OP_DELETE = 2006
|
10
|
-
OP_KILL_CURSORS = 2007
|
11
|
-
|
12
|
-
OP_QUERY_SLAVE_OK = 4
|
13
|
-
OP_QUERY_NO_CURSOR_TIMEOUT = 16
|
14
|
-
end
|
15
|
-
end
|