mongo 0.1.0 → 0.15
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 +268 -71
- data/Rakefile +27 -62
- data/bin/bson_benchmark.rb +59 -0
- data/bin/mongo_console +3 -3
- data/bin/run_test_script +19 -0
- data/bin/standard_benchmark +109 -0
- data/examples/admin.rb +41 -0
- data/examples/benchmarks.rb +42 -0
- data/examples/blog.rb +76 -0
- data/examples/capped.rb +23 -0
- data/examples/cursor.rb +47 -0
- data/examples/gridfs.rb +87 -0
- data/examples/index_test.rb +125 -0
- data/examples/info.rb +30 -0
- data/examples/queries.rb +69 -0
- data/examples/simple.rb +23 -0
- data/examples/strict.rb +34 -0
- data/examples/types.rb +35 -0
- data/lib/mongo.rb +9 -2
- data/lib/mongo/admin.rb +65 -68
- data/lib/mongo/collection.rb +379 -117
- data/lib/mongo/connection.rb +151 -0
- data/lib/mongo/cursor.rb +271 -216
- data/lib/mongo/db.rb +500 -315
- data/lib/mongo/errors.rb +26 -0
- data/lib/mongo/gridfs.rb +16 -0
- data/lib/mongo/gridfs/chunk.rb +92 -0
- data/lib/mongo/gridfs/grid_store.rb +464 -0
- data/lib/mongo/message.rb +16 -0
- data/lib/mongo/message/get_more_message.rb +24 -13
- data/lib/mongo/message/insert_message.rb +29 -11
- data/lib/mongo/message/kill_cursors_message.rb +23 -12
- data/lib/mongo/message/message.rb +74 -62
- data/lib/mongo/message/message_header.rb +35 -24
- data/lib/mongo/message/msg_message.rb +21 -9
- data/lib/mongo/message/opcodes.rb +26 -15
- data/lib/mongo/message/query_message.rb +63 -43
- data/lib/mongo/message/remove_message.rb +29 -12
- data/lib/mongo/message/update_message.rb +30 -13
- data/lib/mongo/query.rb +97 -89
- data/lib/mongo/types/binary.rb +25 -21
- data/lib/mongo/types/code.rb +30 -0
- data/lib/mongo/types/dbref.rb +19 -23
- data/lib/mongo/types/objectid.rb +130 -116
- data/lib/mongo/types/regexp_of_holding.rb +27 -31
- data/lib/mongo/util/bson.rb +273 -160
- data/lib/mongo/util/byte_buffer.rb +32 -28
- data/lib/mongo/util/ordered_hash.rb +88 -42
- data/lib/mongo/util/xml_to_ruby.rb +18 -15
- data/mongo-ruby-driver.gemspec +103 -0
- data/test/mongo-qa/_common.rb +8 -0
- data/test/mongo-qa/admin +26 -0
- data/test/mongo-qa/capped +22 -0
- data/test/mongo-qa/count1 +18 -0
- data/test/mongo-qa/dbs +22 -0
- data/test/mongo-qa/find +10 -0
- data/test/mongo-qa/find1 +15 -0
- data/test/mongo-qa/gridfs_in +16 -0
- data/test/mongo-qa/gridfs_out +17 -0
- data/test/mongo-qa/indices +49 -0
- data/test/mongo-qa/remove +25 -0
- data/test/mongo-qa/stress1 +35 -0
- data/test/mongo-qa/test1 +11 -0
- data/test/mongo-qa/update +18 -0
- data/{tests → test}/test_admin.rb +25 -16
- data/test/test_bson.rb +268 -0
- data/{tests → test}/test_byte_buffer.rb +0 -0
- data/test/test_chunk.rb +84 -0
- data/test/test_collection.rb +282 -0
- data/test/test_connection.rb +101 -0
- data/test/test_cursor.rb +321 -0
- data/test/test_db.rb +196 -0
- data/test/test_db_api.rb +798 -0
- data/{tests → test}/test_db_connection.rb +4 -3
- data/test/test_grid_store.rb +284 -0
- data/{tests → test}/test_message.rb +1 -1
- data/test/test_objectid.rb +105 -0
- data/{tests → test}/test_ordered_hash.rb +55 -0
- data/{tests → test}/test_round_trip.rb +13 -9
- data/test/test_threading.rb +37 -0
- metadata +74 -32
- data/bin/validate +0 -51
- data/lib/mongo/mongo.rb +0 -74
- data/lib/mongo/types/undefined.rb +0 -31
- data/tests/test_bson.rb +0 -135
- data/tests/test_cursor.rb +0 -66
- data/tests/test_db.rb +0 -51
- data/tests/test_db_api.rb +0 -349
- data/tests/test_objectid.rb +0 -88
data/lib/mongo/message.rb
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
1
17
|
%w(get_more_message insert_message kill_cursors_message message_header
|
2
18
|
msg_message query_message remove_message update_message).each { |f|
|
3
19
|
require "mongo/message/#{f}"
|
@@ -1,21 +1,32 @@
|
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
1
17
|
require 'mongo/message/message'
|
2
18
|
require 'mongo/message/opcodes'
|
3
19
|
|
4
|
-
module
|
5
|
-
module Mongo
|
6
|
-
module Driver
|
20
|
+
module Mongo
|
7
21
|
|
8
|
-
|
22
|
+
class GetMoreMessage < Message
|
9
23
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
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)
|
18
30
|
end
|
19
31
|
end
|
20
32
|
end
|
21
|
-
|
@@ -1,19 +1,37 @@
|
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
1
17
|
require 'mongo/message/message'
|
2
18
|
require 'mongo/message/opcodes'
|
3
19
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
20
|
+
module Mongo
|
21
|
+
|
22
|
+
class InsertMessage < Message
|
7
23
|
|
8
|
-
|
24
|
+
def initialize(db_name, collection_name, check_keys=true, *objs)
|
25
|
+
@collection_name = collection_name
|
26
|
+
@objs = objs
|
27
|
+
super(OP_INSERT)
|
28
|
+
write_int(0)
|
29
|
+
write_string("#{db_name}.#{collection_name}")
|
30
|
+
objs.each { |o| write_doc(o, check_keys) }
|
31
|
+
end
|
9
32
|
|
10
|
-
|
11
|
-
|
12
|
-
write_int(0)
|
13
|
-
write_string("#{db_name}.#{collection_name}")
|
14
|
-
objs.each { |o| write_doc(o) }
|
15
|
-
end
|
16
|
-
end
|
33
|
+
def to_s
|
34
|
+
"db.#{@collection_name}.insert(#{@objs.inspect})"
|
17
35
|
end
|
18
36
|
end
|
19
37
|
end
|
@@ -1,20 +1,31 @@
|
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
1
17
|
require 'mongo/message/message'
|
2
18
|
require 'mongo/message/opcodes'
|
3
19
|
|
4
|
-
module
|
5
|
-
module Mongo
|
6
|
-
module Driver
|
20
|
+
module Mongo
|
7
21
|
|
8
|
-
|
22
|
+
class KillCursorsMessage < Message
|
9
23
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
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 }
|
17
29
|
end
|
18
30
|
end
|
19
31
|
end
|
20
|
-
|
@@ -1,68 +1,80 @@
|
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
1
17
|
require 'mongo/util/bson'
|
2
18
|
require 'mongo/util/byte_buffer'
|
3
19
|
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@buf.put_long(i)
|
37
|
-
update_message_length
|
38
|
-
end
|
39
|
-
|
40
|
-
def write_string(s)
|
41
|
-
BSON.serialize_cstr(@buf, s)
|
42
|
-
update_message_length
|
43
|
-
end
|
44
|
-
|
45
|
-
def write_doc(hash)
|
46
|
-
@buf.put_array(BSON.new.serialize(hash).to_a)
|
47
|
-
update_message_length
|
48
|
-
end
|
49
|
-
|
50
|
-
def to_a
|
51
|
-
@buf.to_a
|
52
|
-
end
|
53
|
-
|
54
|
-
def dump
|
55
|
-
@buf.dump
|
56
|
-
end
|
57
|
-
|
58
|
-
# Do not call. Private, but kept public for testing.
|
59
|
-
def update_message_length
|
60
|
-
pos = @buf.position
|
61
|
-
@buf.put_int(@buf.size, 0)
|
62
|
-
@buf.position = pos
|
63
|
-
end
|
64
|
-
|
65
|
-
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)
|
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
|
66
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
|
+
|
67
79
|
end
|
68
80
|
end
|
@@ -1,34 +1,45 @@
|
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
1
17
|
require 'mongo/util/byte_buffer'
|
2
18
|
|
3
|
-
module
|
4
|
-
module Mongo
|
5
|
-
module Driver
|
19
|
+
module Mongo
|
6
20
|
|
7
|
-
|
21
|
+
class MessageHeader
|
8
22
|
|
9
|
-
|
23
|
+
HEADER_SIZE = 16
|
10
24
|
|
11
|
-
|
12
|
-
|
13
|
-
|
25
|
+
def initialize()
|
26
|
+
@buf = ByteBuffer.new
|
27
|
+
end
|
14
28
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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
|
26
40
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
41
|
+
def dump
|
42
|
+
@buf.dump
|
31
43
|
end
|
32
44
|
end
|
33
45
|
end
|
34
|
-
|
@@ -1,17 +1,29 @@
|
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
|
+
|
1
17
|
require 'mongo/message/message'
|
2
18
|
require 'mongo/message/opcodes'
|
3
19
|
|
4
|
-
module
|
5
|
-
module Mongo
|
6
|
-
module Driver
|
20
|
+
module Mongo
|
7
21
|
|
8
|
-
|
22
|
+
class MsgMessage < Message
|
9
23
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
end
|
24
|
+
def initialize(msg)
|
25
|
+
super(OP_MSG)
|
26
|
+
write_string(msg)
|
15
27
|
end
|
16
28
|
end
|
17
29
|
end
|
@@ -1,16 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
# --
|
2
|
+
# Copyright (C) 2008-2009 10gen Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
# ++
|
16
16
|
|
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
|
27
|
+
end
|