mongodb-mongo 0.12 → 0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +12 -12
- data/Rakefile +1 -1
- data/bin/bson_benchmark.rb +1 -1
- data/bin/mongo_console +3 -3
- data/bin/run_test_script +2 -2
- data/bin/standard_benchmark +3 -3
- data/examples/admin.rb +3 -3
- data/examples/benchmarks.rb +2 -2
- data/examples/blog.rb +4 -4
- data/examples/capped.rb +3 -3
- data/examples/cursor.rb +3 -3
- data/examples/gridfs.rb +4 -4
- data/examples/index_test.rb +11 -11
- data/examples/info.rb +3 -3
- data/examples/queries.rb +3 -3
- data/examples/simple.rb +3 -3
- data/examples/strict.rb +3 -3
- data/examples/types.rb +4 -9
- data/lib/mongo.rb +35 -3
- data/lib/mongo/admin.rb +56 -60
- data/lib/mongo/collection.rb +368 -320
- data/lib/mongo/connection.rb +166 -0
- data/lib/mongo/cursor.rb +206 -209
- data/lib/mongo/db.rb +478 -489
- data/lib/mongo/errors.rb +8 -9
- data/lib/mongo/gridfs/chunk.rb +66 -70
- data/lib/mongo/gridfs/grid_store.rb +406 -410
- data/lib/mongo/message/get_more_message.rb +8 -13
- data/lib/mongo/message/insert_message.rb +7 -11
- data/lib/mongo/message/kill_cursors_message.rb +7 -12
- data/lib/mongo/message/message.rb +58 -62
- data/lib/mongo/message/message_header.rb +19 -24
- data/lib/mongo/message/msg_message.rb +5 -9
- data/lib/mongo/message/opcodes.rb +10 -15
- data/lib/mongo/message/query_message.rb +42 -46
- data/lib/mongo/message/remove_message.rb +8 -12
- data/lib/mongo/message/update_message.rb +9 -13
- data/lib/mongo/query.rb +84 -88
- data/lib/mongo/types/binary.rb +13 -17
- data/lib/mongo/types/code.rb +9 -13
- data/lib/mongo/types/dbref.rb +10 -14
- data/lib/mongo/types/objectid.rb +103 -107
- data/lib/mongo/types/regexp_of_holding.rb +18 -22
- data/lib/mongo/types/undefined.rb +7 -10
- data/lib/mongo/util/bson.rb +4 -9
- data/lib/mongo/util/xml_to_ruby.rb +1 -3
- data/mongo-ruby-driver.gemspec +33 -32
- data/{tests → test}/mongo-qa/_common.rb +1 -1
- data/{tests → test}/mongo-qa/admin +1 -1
- data/{tests → test}/mongo-qa/capped +1 -1
- data/{tests → test}/mongo-qa/count1 +4 -4
- data/{tests → test}/mongo-qa/dbs +1 -1
- data/{tests → test}/mongo-qa/find +1 -1
- data/{tests → test}/mongo-qa/find1 +1 -1
- data/{tests → test}/mongo-qa/gridfs_in +2 -2
- data/{tests → test}/mongo-qa/gridfs_out +2 -2
- data/{tests → test}/mongo-qa/indices +2 -2
- data/{tests → test}/mongo-qa/remove +1 -1
- data/{tests → test}/mongo-qa/stress1 +1 -1
- data/{tests → test}/mongo-qa/test1 +1 -1
- data/{tests → test}/mongo-qa/update +1 -1
- data/{tests → test}/test_admin.rb +3 -3
- data/{tests → test}/test_bson.rb +4 -4
- data/{tests → test}/test_byte_buffer.rb +0 -0
- data/{tests → test}/test_chunk.rb +4 -4
- data/{tests → test}/test_collection.rb +42 -4
- data/{tests/test_mongo.rb → test/test_connection.rb} +35 -11
- data/test/test_cursor.rb +223 -0
- data/{tests → test}/test_db.rb +12 -12
- data/{tests → test}/test_db_api.rb +28 -33
- data/{tests → test}/test_db_connection.rb +3 -3
- data/{tests → test}/test_grid_store.rb +4 -4
- data/{tests → test}/test_message.rb +1 -1
- data/{tests → test}/test_objectid.rb +3 -3
- data/{tests → test}/test_ordered_hash.rb +0 -0
- data/{tests → test}/test_round_trip.rb +6 -2
- data/{tests → test}/test_threading.rb +3 -3
- data/test/test_xgen.rb +73 -0
- metadata +33 -32
- data/lib/mongo/mongo.rb +0 -164
- data/tests/test_cursor.rb +0 -121
@@ -17,21 +17,16 @@
|
|
17
17
|
require 'mongo/message/message'
|
18
18
|
require 'mongo/message/opcodes'
|
19
19
|
|
20
|
-
module
|
21
|
-
module Mongo
|
22
|
-
module Driver
|
20
|
+
module Mongo
|
23
21
|
|
24
|
-
|
22
|
+
class GetMoreMessage < Message
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
24
|
+
def initialize(db_name, collection_name, cursor)
|
25
|
+
super(OP_GET_MORE)
|
26
|
+
write_int(0)
|
27
|
+
write_string("#{db_name}.#{collection_name}")
|
28
|
+
write_int(0) # num to return; leave it up to the db for now
|
29
|
+
write_long(cursor)
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
37
|
-
|
@@ -17,19 +17,15 @@
|
|
17
17
|
require 'mongo/message/message'
|
18
18
|
require 'mongo/message/opcodes'
|
19
19
|
|
20
|
-
module
|
21
|
-
module Mongo
|
22
|
-
module Driver
|
20
|
+
module Mongo
|
23
21
|
|
24
|
-
|
22
|
+
class InsertMessage < Message
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
24
|
+
def initialize(db_name, collection_name, check_keys=true, *objs)
|
25
|
+
super(OP_INSERT)
|
26
|
+
write_int(0)
|
27
|
+
write_string("#{db_name}.#{collection_name}")
|
28
|
+
objs.each { |o| write_doc(o, check_keys) }
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
@@ -17,20 +17,15 @@
|
|
17
17
|
require 'mongo/message/message'
|
18
18
|
require 'mongo/message/opcodes'
|
19
19
|
|
20
|
-
module
|
21
|
-
module Mongo
|
22
|
-
module Driver
|
20
|
+
module Mongo
|
23
21
|
|
24
|
-
|
22
|
+
class KillCursorsMessage < Message
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
24
|
+
def initialize(*cursors)
|
25
|
+
super(OP_KILL_CURSORS)
|
26
|
+
write_int(0)
|
27
|
+
write_int(cursors.length)
|
28
|
+
cursors.each { |c| write_long c }
|
33
29
|
end
|
34
30
|
end
|
35
31
|
end
|
36
|
-
|
@@ -17,68 +17,64 @@
|
|
17
17
|
require 'mongo/util/bson'
|
18
18
|
require 'mongo/util/byte_buffer'
|
19
19
|
|
20
|
-
module
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@buf.put_int(0) # response_to
|
43
|
-
@buf.put_int(op)
|
44
|
-
end
|
45
|
-
|
46
|
-
def write_int(i)
|
47
|
-
@buf.put_int(i)
|
48
|
-
update_message_length
|
49
|
-
end
|
50
|
-
|
51
|
-
def write_long(i)
|
52
|
-
@buf.put_long(i)
|
53
|
-
update_message_length
|
54
|
-
end
|
55
|
-
|
56
|
-
def write_string(s)
|
57
|
-
BSON.serialize_cstr(@buf, s)
|
58
|
-
update_message_length
|
59
|
-
end
|
60
|
-
|
61
|
-
def write_doc(hash, check_keys=false)
|
62
|
-
@buf.put_array(BSON.new.serialize(hash, check_keys).to_a)
|
63
|
-
update_message_length
|
64
|
-
end
|
65
|
-
|
66
|
-
def to_a
|
67
|
-
@buf.to_a
|
68
|
-
end
|
69
|
-
|
70
|
-
def dump
|
71
|
-
@buf.dump
|
72
|
-
end
|
73
|
-
|
74
|
-
# Do not call. Private, but kept public for testing.
|
75
|
-
def update_message_length
|
76
|
-
pos = @buf.position
|
77
|
-
@buf.put_int(@buf.size, 0)
|
78
|
-
@buf.position = pos
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
20
|
+
module Mongo
|
21
|
+
|
22
|
+
class Message
|
23
|
+
|
24
|
+
HEADER_SIZE = 16 # size, id, response_to, opcode
|
25
|
+
|
26
|
+
@@class_req_id = 0
|
27
|
+
|
28
|
+
attr_reader :buf # for testing
|
29
|
+
|
30
|
+
def initialize(op)
|
31
|
+
@op = op
|
32
|
+
@message_length = HEADER_SIZE
|
33
|
+
@data_length = 0
|
34
|
+
@request_id = (@@class_req_id += 1)
|
35
|
+
@response_id = 0
|
36
|
+
@buf = ByteBuffer.new
|
37
|
+
|
38
|
+
@buf.put_int(16) # holder for length
|
39
|
+
@buf.put_int(@request_id)
|
40
|
+
@buf.put_int(0) # response_to
|
41
|
+
@buf.put_int(op)
|
82
42
|
end
|
43
|
+
|
44
|
+
def write_int(i)
|
45
|
+
@buf.put_int(i)
|
46
|
+
update_message_length
|
47
|
+
end
|
48
|
+
|
49
|
+
def write_long(i)
|
50
|
+
@buf.put_long(i)
|
51
|
+
update_message_length
|
52
|
+
end
|
53
|
+
|
54
|
+
def write_string(s)
|
55
|
+
BSON.serialize_cstr(@buf, s)
|
56
|
+
update_message_length
|
57
|
+
end
|
58
|
+
|
59
|
+
def write_doc(hash, check_keys=false)
|
60
|
+
@buf.put_array(BSON.new.serialize(hash, check_keys).to_a)
|
61
|
+
update_message_length
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_a
|
65
|
+
@buf.to_a
|
66
|
+
end
|
67
|
+
|
68
|
+
def dump
|
69
|
+
@buf.dump
|
70
|
+
end
|
71
|
+
|
72
|
+
# Do not call. Private, but kept public for testing.
|
73
|
+
def update_message_length
|
74
|
+
pos = @buf.position
|
75
|
+
@buf.put_int(@buf.size, 0)
|
76
|
+
@buf.position = pos
|
77
|
+
end
|
78
|
+
|
83
79
|
end
|
84
80
|
end
|
@@ -16,35 +16,30 @@
|
|
16
16
|
|
17
17
|
require 'mongo/util/byte_buffer'
|
18
18
|
|
19
|
-
module
|
20
|
-
module Mongo
|
21
|
-
module Driver
|
19
|
+
module Mongo
|
22
20
|
|
23
|
-
|
21
|
+
class MessageHeader
|
24
22
|
|
25
|
-
|
23
|
+
HEADER_SIZE = 16
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
25
|
+
def initialize()
|
26
|
+
@buf = ByteBuffer.new
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
def read_header(db)
|
30
|
+
@buf.rewind
|
31
|
+
@buf.put_array(db.receive_full(HEADER_SIZE).unpack("C*"))
|
32
|
+
raise "Short read for DB response header: expected #{HEADER_SIZE} bytes, saw #{@buf.size}" unless @buf.size == HEADER_SIZE
|
33
|
+
@buf.rewind
|
34
|
+
@size = @buf.get_int
|
35
|
+
@request_id = @buf.get_int
|
36
|
+
@response_to = @buf.get_int
|
37
|
+
@op = @buf.get_int
|
38
|
+
self
|
39
|
+
end
|
42
40
|
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
41
|
+
def dump
|
42
|
+
@buf.dump
|
47
43
|
end
|
48
44
|
end
|
49
45
|
end
|
50
|
-
|
@@ -17,17 +17,13 @@
|
|
17
17
|
require 'mongo/message/message'
|
18
18
|
require 'mongo/message/opcodes'
|
19
19
|
|
20
|
-
module
|
21
|
-
module Mongo
|
22
|
-
module Driver
|
20
|
+
module Mongo
|
23
21
|
|
24
|
-
|
22
|
+
class MsgMessage < Message
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
24
|
+
def initialize(msg)
|
25
|
+
super(OP_MSG)
|
26
|
+
write_string(msg)
|
31
27
|
end
|
32
28
|
end
|
33
29
|
end
|
@@ -14,19 +14,14 @@
|
|
14
14
|
# limitations under the License.
|
15
15
|
# ++
|
16
16
|
|
17
|
-
module
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
OP_DELETE = 2006
|
28
|
-
OP_KILL_CURSORS = 2007
|
29
|
-
end
|
30
|
-
end
|
17
|
+
module Mongo
|
18
|
+
OP_REPLY = 1 # reply. responseTo is set.
|
19
|
+
OP_MSG = 1000 # generic msg command followed by a string
|
20
|
+
OP_UPDATE = 2001 # update object
|
21
|
+
OP_INSERT = 2002
|
22
|
+
# GET_BY_OID = 2003
|
23
|
+
OP_QUERY = 2004
|
24
|
+
OP_GET_MORE = 2005
|
25
|
+
OP_DELETE = 2006
|
26
|
+
OP_KILL_CURSORS = 2007
|
31
27
|
end
|
32
|
-
|
@@ -18,60 +18,56 @@ require 'mongo/message/message'
|
|
18
18
|
require 'mongo/message/opcodes'
|
19
19
|
require 'mongo/util/ordered_hash'
|
20
20
|
|
21
|
-
module
|
22
|
-
module Mongo
|
23
|
-
module Driver
|
21
|
+
module Mongo
|
24
22
|
|
25
|
-
|
23
|
+
class QueryMessage < Message
|
26
24
|
|
27
|
-
|
25
|
+
attr_reader :query
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
27
|
+
def initialize(db_name, collection_name, query)
|
28
|
+
super(OP_QUERY)
|
29
|
+
@query = query
|
30
|
+
write_int(0)
|
31
|
+
write_string("#{db_name}.#{collection_name}")
|
32
|
+
write_int(query.number_to_skip)
|
33
|
+
write_int(-query.number_to_return) # Negative means hard limit
|
34
|
+
sel = query.selector
|
35
|
+
if query.contains_special_fields
|
36
|
+
sel = OrderedHash.new
|
37
|
+
sel['query'] = query.selector
|
38
|
+
if query.order_by && query.order_by.length > 0
|
39
|
+
sel['orderby'] = case query.order_by
|
40
|
+
when String
|
41
|
+
{query.order_by => 1}
|
42
|
+
when Array
|
43
|
+
h = OrderedHash.new
|
44
|
+
query.order_by.each { |ob|
|
45
|
+
case ob
|
42
46
|
when String
|
43
|
-
|
44
|
-
when
|
45
|
-
h =
|
46
|
-
query.order_by.each { |ob|
|
47
|
-
case ob
|
48
|
-
when String
|
49
|
-
h[ob] = 1
|
50
|
-
when Hash # should have one entry; will handle all
|
51
|
-
ob.each { |k,v| h[k] = v }
|
52
|
-
else
|
53
|
-
raise "illegal query order_by value #{query.order_by.inspect}"
|
54
|
-
end
|
55
|
-
}
|
56
|
-
h
|
57
|
-
when Hash # Should be an ordered hash, but this message doesn't care
|
58
|
-
query.order_by
|
47
|
+
h[ob] = 1
|
48
|
+
when Hash # should have one entry; will handle all
|
49
|
+
ob.each { |k,v| h[k] = v }
|
59
50
|
else
|
60
|
-
raise "illegal order_by
|
51
|
+
raise "illegal query order_by value #{query.order_by.inspect}"
|
61
52
|
end
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
def first_key(key)
|
72
|
-
@first_key = key
|
53
|
+
}
|
54
|
+
h
|
55
|
+
when Hash # Should be an ordered hash, but this message doesn't care
|
56
|
+
query.order_by
|
57
|
+
else
|
58
|
+
raise "illegal order_by: is a #{query.order_by.class.name}, must be String, Array, Hash, or OrderedHash"
|
59
|
+
end
|
73
60
|
end
|
61
|
+
sel['$hint'] = query.hint if query.hint && query.hint.length > 0
|
62
|
+
sel['$explain'] = true if query.explain
|
63
|
+
sel['$snapshot'] = true if query.snapshot
|
74
64
|
end
|
65
|
+
write_doc(sel)
|
66
|
+
write_doc(query.fields) if query.fields
|
67
|
+
end
|
68
|
+
|
69
|
+
def first_key(key)
|
70
|
+
@first_key = key
|
75
71
|
end
|
76
72
|
end
|
77
73
|
end
|
@@ -17,20 +17,16 @@
|
|
17
17
|
require 'mongo/message/message'
|
18
18
|
require 'mongo/message/opcodes'
|
19
19
|
|
20
|
-
module
|
21
|
-
module Mongo
|
22
|
-
module Driver
|
20
|
+
module Mongo
|
23
21
|
|
24
|
-
|
22
|
+
class RemoveMessage < Message
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
end
|
33
|
-
end
|
24
|
+
def initialize(db_name, collection_name, sel)
|
25
|
+
super(OP_DELETE)
|
26
|
+
write_int(0)
|
27
|
+
write_string("#{db_name}.#{collection_name}")
|
28
|
+
write_int(0) # flags?
|
29
|
+
write_doc(sel)
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|