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.
Files changed (89) hide show
  1. data/README.rdoc +268 -71
  2. data/Rakefile +27 -62
  3. data/bin/bson_benchmark.rb +59 -0
  4. data/bin/mongo_console +3 -3
  5. data/bin/run_test_script +19 -0
  6. data/bin/standard_benchmark +109 -0
  7. data/examples/admin.rb +41 -0
  8. data/examples/benchmarks.rb +42 -0
  9. data/examples/blog.rb +76 -0
  10. data/examples/capped.rb +23 -0
  11. data/examples/cursor.rb +47 -0
  12. data/examples/gridfs.rb +87 -0
  13. data/examples/index_test.rb +125 -0
  14. data/examples/info.rb +30 -0
  15. data/examples/queries.rb +69 -0
  16. data/examples/simple.rb +23 -0
  17. data/examples/strict.rb +34 -0
  18. data/examples/types.rb +35 -0
  19. data/lib/mongo.rb +9 -2
  20. data/lib/mongo/admin.rb +65 -68
  21. data/lib/mongo/collection.rb +379 -117
  22. data/lib/mongo/connection.rb +151 -0
  23. data/lib/mongo/cursor.rb +271 -216
  24. data/lib/mongo/db.rb +500 -315
  25. data/lib/mongo/errors.rb +26 -0
  26. data/lib/mongo/gridfs.rb +16 -0
  27. data/lib/mongo/gridfs/chunk.rb +92 -0
  28. data/lib/mongo/gridfs/grid_store.rb +464 -0
  29. data/lib/mongo/message.rb +16 -0
  30. data/lib/mongo/message/get_more_message.rb +24 -13
  31. data/lib/mongo/message/insert_message.rb +29 -11
  32. data/lib/mongo/message/kill_cursors_message.rb +23 -12
  33. data/lib/mongo/message/message.rb +74 -62
  34. data/lib/mongo/message/message_header.rb +35 -24
  35. data/lib/mongo/message/msg_message.rb +21 -9
  36. data/lib/mongo/message/opcodes.rb +26 -15
  37. data/lib/mongo/message/query_message.rb +63 -43
  38. data/lib/mongo/message/remove_message.rb +29 -12
  39. data/lib/mongo/message/update_message.rb +30 -13
  40. data/lib/mongo/query.rb +97 -89
  41. data/lib/mongo/types/binary.rb +25 -21
  42. data/lib/mongo/types/code.rb +30 -0
  43. data/lib/mongo/types/dbref.rb +19 -23
  44. data/lib/mongo/types/objectid.rb +130 -116
  45. data/lib/mongo/types/regexp_of_holding.rb +27 -31
  46. data/lib/mongo/util/bson.rb +273 -160
  47. data/lib/mongo/util/byte_buffer.rb +32 -28
  48. data/lib/mongo/util/ordered_hash.rb +88 -42
  49. data/lib/mongo/util/xml_to_ruby.rb +18 -15
  50. data/mongo-ruby-driver.gemspec +103 -0
  51. data/test/mongo-qa/_common.rb +8 -0
  52. data/test/mongo-qa/admin +26 -0
  53. data/test/mongo-qa/capped +22 -0
  54. data/test/mongo-qa/count1 +18 -0
  55. data/test/mongo-qa/dbs +22 -0
  56. data/test/mongo-qa/find +10 -0
  57. data/test/mongo-qa/find1 +15 -0
  58. data/test/mongo-qa/gridfs_in +16 -0
  59. data/test/mongo-qa/gridfs_out +17 -0
  60. data/test/mongo-qa/indices +49 -0
  61. data/test/mongo-qa/remove +25 -0
  62. data/test/mongo-qa/stress1 +35 -0
  63. data/test/mongo-qa/test1 +11 -0
  64. data/test/mongo-qa/update +18 -0
  65. data/{tests → test}/test_admin.rb +25 -16
  66. data/test/test_bson.rb +268 -0
  67. data/{tests → test}/test_byte_buffer.rb +0 -0
  68. data/test/test_chunk.rb +84 -0
  69. data/test/test_collection.rb +282 -0
  70. data/test/test_connection.rb +101 -0
  71. data/test/test_cursor.rb +321 -0
  72. data/test/test_db.rb +196 -0
  73. data/test/test_db_api.rb +798 -0
  74. data/{tests → test}/test_db_connection.rb +4 -3
  75. data/test/test_grid_store.rb +284 -0
  76. data/{tests → test}/test_message.rb +1 -1
  77. data/test/test_objectid.rb +105 -0
  78. data/{tests → test}/test_ordered_hash.rb +55 -0
  79. data/{tests → test}/test_round_trip.rb +13 -9
  80. data/test/test_threading.rb +37 -0
  81. metadata +74 -32
  82. data/bin/validate +0 -51
  83. data/lib/mongo/mongo.rb +0 -74
  84. data/lib/mongo/types/undefined.rb +0 -31
  85. data/tests/test_bson.rb +0 -135
  86. data/tests/test_cursor.rb +0 -66
  87. data/tests/test_db.rb +0 -51
  88. data/tests/test_db_api.rb +0 -349
  89. data/tests/test_objectid.rb +0 -88
@@ -0,0 +1,125 @@
1
+ class Exception
2
+ def errmsg
3
+ "%s: %s\n%s" % [self.class, message, (backtrace || []).join("\n") << "\n"]
4
+ end
5
+ end
6
+
7
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
8
+ require 'mongo'
9
+
10
+ include Mongo
11
+
12
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
13
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
14
+
15
+ puts ">> Connecting to #{host}:#{port}"
16
+ db = Connection.new(host, port).db('ruby-mongo-index_test')
17
+
18
+ puts ">> Dropping collection test"
19
+ begin
20
+ res = db.drop_collection('test')
21
+ puts "dropped : #{res.inspect}"
22
+ rescue => e
23
+ puts "Error: #{e.errmsg}"
24
+ end
25
+
26
+ puts ">> Creating collection test"
27
+ begin
28
+ coll = db.collection('test')
29
+ puts "created : #{coll.inspect}"
30
+ rescue => e
31
+ puts "Error: #{e.errmsg}"
32
+ end
33
+
34
+ OBJS_COUNT = 100
35
+
36
+ puts ">> Generating test data"
37
+ msgs = %w{hola hello aloha ciao}
38
+ arr = (0...OBJS_COUNT).collect {|x| { :number => x, :rndm => (rand(5)+1), :msg => msgs[rand(4)] }}
39
+ puts "generated"
40
+
41
+ puts ">> Inserting data (#{arr.size})"
42
+ coll.insert(arr)
43
+ puts "inserted"
44
+
45
+ puts ">> Creating index"
46
+ res = coll.create_index "all", :_id => 1, :number => 1, :rndm => 1, :msg => 1
47
+ # res = coll.create_index "all", '_id' => 1, 'number' => 1, 'rndm' => 1, 'msg' => 1
48
+ puts "created index: #{res.inspect}"
49
+ # ============================ Mongo Log ============================
50
+ # Fri Dec 5 14:45:02 Adding all existing records for ruby-mongo-console.test to new index
51
+ # ***
52
+ # Bad data or size in BSONElement::size()
53
+ # bad type:30
54
+ # totalsize:11 fieldnamesize:4
55
+ # lastrec:
56
+ # Fri Dec 5 14:45:02 ruby-mongo-console.system.indexes Assertion failure false jsobj.cpp a0
57
+ # Fri Dec 5 14:45:02 database: ruby-mongo-console op:7d2 0
58
+ # Fri Dec 5 14:45:02 ns: ruby-mongo-console.system.indexes
59
+
60
+ puts ">> Gathering index information"
61
+ begin
62
+ res = coll.index_information
63
+ puts "index_information : #{res.inspect}"
64
+ rescue => e
65
+ puts "Error: #{e.errmsg}"
66
+ end
67
+ # ============================ Console Output ============================
68
+ # RuntimeError: Keys for index on return from db was nil. Coll = ruby-mongo-console.test
69
+ # from ./bin/../lib/mongo/db.rb:135:in `index_information'
70
+ # from (irb):11:in `collect'
71
+ # from ./bin/../lib/mongo/cursor.rb:47:in `each'
72
+ # from ./bin/../lib/mongo/db.rb:130:in `collect'
73
+ # from ./bin/../lib/mongo/db.rb:130:in `index_information'
74
+ # from ./bin/../lib/mongo/collection.rb:74:in `index_information'
75
+ # from (irb):11
76
+
77
+ puts ">> Dropping index"
78
+ begin
79
+ res = coll.drop_index "all_1"
80
+ puts "dropped : #{res.inspect}"
81
+ rescue => e
82
+ puts "Error: #{e.errmsg}"
83
+ end
84
+
85
+ # ============================ Console Output ============================
86
+ # => {"nIndexesWas"=>2.0, "ok"=>1.0}
87
+ # ============================ Mongo Log ============================
88
+ # 0x41802a 0x411549 0x42bac6 0x42c1f6 0x42c55b 0x42e6f7 0x41631e 0x41a89d 0x41ade2 0x41b448 0x4650d2 0x4695ad
89
+ # db/db(_Z12sayDbContextPKc+0x17a) [0x41802a]
90
+ # db/db(_Z8assertedPKcS0_j+0x9) [0x411549]
91
+ # db/db(_ZNK11BSONElement4sizeEv+0x1f6) [0x42bac6]
92
+ # db/db(_ZN7BSONObj8getFieldEPKc+0xa6) [0x42c1f6]
93
+ # db/db(_ZN7BSONObj14getFieldDottedEPKc+0x11b) [0x42c55b]
94
+ # db/db(_ZN7BSONObj19extractFieldsDottedES_R14BSONObjBuilder+0x87) [0x42e6f7]
95
+ # db/db(_ZN12IndexDetails17getKeysFromObjectER7BSONObjRSt3setIS0_St4lessIS0_ESaIS0_EE+0x24e) [0x41631e]
96
+ # db/db(_Z12_indexRecordR12IndexDetailsR7BSONObj7DiskLoc+0x5d) [0x41a89d]
97
+ # db/db(_Z18addExistingToIndexPKcR12IndexDetails+0xb2) [0x41ade2]
98
+ # db/db(_ZN11DataFileMgr6insertEPKcPKvib+0x508) [0x41b448]
99
+ # db/db(_Z14receivedInsertR7MessageRSt18basic_stringstreamIcSt11char_traitsIcESaIcEE+0x112) [0x4650d2]
100
+ # db/db(_Z10connThreadv+0xb4d) [0x4695ad]
101
+ # Fri Dec 5 14:45:02 ruby-mongo-console.system.indexes Caught Assertion insert, continuing
102
+ # Fri Dec 5 14:47:59 CMD: deleteIndexes ruby-mongo-console.test
103
+ # d->nIndexes was 2
104
+ # alpha implementation, space not reclaimed
105
+
106
+ puts ">> Gathering index information"
107
+ begin
108
+ res = coll.index_information
109
+ puts "index_information : #{res.inspect}"
110
+ rescue => e
111
+ puts "Error: #{e.errmsg}"
112
+ end
113
+ # ============================ Console Output ============================
114
+ # RuntimeError: Keys for index on return from db was nil. Coll = ruby-mongo-console.test
115
+ # from ./bin/../lib/mongo/db.rb:135:in `index_information'
116
+ # from (irb):15:in `collect'
117
+ # from ./bin/../lib/mongo/cursor.rb:47:in `each'
118
+ # from ./bin/../lib/mongo/db.rb:130:in `collect'
119
+ # from ./bin/../lib/mongo/db.rb:130:in `index_information'
120
+ # from ./bin/../lib/mongo/collection.rb:74:in `index_information'
121
+ # from (irb):15
122
+
123
+ puts ">> Closing connection"
124
+ db.close
125
+ puts "closed"
@@ -0,0 +1,30 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+
4
+ include Mongo
5
+
6
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
8
+
9
+ puts "Connecting to #{host}:#{port}"
10
+ db = Connection.new(host, port).db('ruby-mongo-examples')
11
+ coll = db.collection('test')
12
+
13
+ # Erase all records from collection, if any
14
+ coll.clear
15
+
16
+ # Insert 3 records
17
+ 3.times { |i| coll.insert({'a' => i+1}) }
18
+
19
+ # Collection names in database
20
+ p db.collection_names
21
+
22
+ # More information about each collection
23
+ p db.collections_info
24
+
25
+ # Index information
26
+ db.create_index('test', 'a')
27
+ p db.index_information('test')
28
+
29
+ # Destroy the collection
30
+ coll.drop
@@ -0,0 +1,69 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'pp'
4
+
5
+ include Mongo
6
+
7
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
9
+
10
+ puts "Connecting to #{host}:#{port}"
11
+ db = Connection.new(host, port).db('ruby-mongo-examples')
12
+ coll = db.collection('test')
13
+
14
+ # Remove all records, if any
15
+ coll.clear
16
+
17
+ # Insert three records
18
+ coll.insert('a' => 1)
19
+ coll.insert('a' => 2)
20
+ coll.insert('b' => 3)
21
+
22
+ # Count.
23
+ puts "There are #{coll.count()} records."
24
+
25
+ # Find all records. find() returns a Cursor.
26
+ cursor = coll.find()
27
+
28
+ # Print them. Note that all records have an _id automatically added by the
29
+ # database. See pk.rb for an example of how to use a primary key factory to
30
+ # generate your own values for _id.
31
+ cursor.each { |row| pp row }
32
+
33
+ # Cursor has a to_a method that slurps all records into memory.
34
+ rows = coll.find().to_a
35
+ rows.each { |row| pp row }
36
+
37
+ # See Collection#find. From now on in this file, we won't be printing the
38
+ # records we find.
39
+ coll.find('a' => 1)
40
+
41
+ # Find records sort by 'a', skip 1, limit 2 records.
42
+ # Sort can be single name, array, or hash.
43
+ coll.find({}, {:skip => 1, :limit => 2, :sort => 'a'})
44
+
45
+ # Find all records with 'a' > 1. There is also $lt, $gte, and $lte.
46
+ coll.find({'a' => {'$gt' => 1}})
47
+ coll.find({'a' => {'$gt' => 1, '$lte' => 3}})
48
+
49
+ # Find all records with 'a' in a set of values.
50
+ coll.find('a' => {'$in' => [1,2]})
51
+
52
+ # Find by regexp
53
+ coll.find('a' => /[1|2]/)
54
+
55
+ # Print query explanation
56
+ pp coll.find('a' => /[1|2]/).explain()
57
+
58
+ # Use a hint with a query. Need an index. Hints can be stored with the
59
+ # collection, in which case they will be used with all queries, or they can be
60
+ # specified per query, in which case that hint overrides the hint associated
61
+ # with the collection if any.
62
+ coll.create_index('a')
63
+ coll.hint = 'a'
64
+
65
+ # You will see a different explanation now that the hint is in place
66
+ pp coll.find('a' => /[1|2]/).explain()
67
+
68
+ # Override hint for single query
69
+ coll.find({'a' => 1}, :hint => 'b')
@@ -0,0 +1,23 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+
4
+ include Mongo
5
+
6
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
8
+
9
+ puts "Connecting to #{host}:#{port}"
10
+ db = Connection.new(host, port).db('ruby-mongo-examples')
11
+ coll = db.collection('test')
12
+
13
+ # Erase all records from collection, if any
14
+ coll.clear
15
+
16
+ # Insert 3 records
17
+ 3.times { |i| coll.insert({'a' => i+1}) }
18
+
19
+ puts "There are #{coll.count()} records in the test collection. Here they are:"
20
+ coll.find().each { |doc| puts doc.inspect }
21
+
22
+ # Destroy the collection
23
+ coll.drop
@@ -0,0 +1,34 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+
4
+ include Mongo
5
+
6
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
7
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
8
+
9
+ puts "Connecting to #{host}:#{port}"
10
+ db = Connection.new(host, port).db('ruby-mongo-examples')
11
+
12
+ db.drop_collection('does-not-exist')
13
+ db.create_collection('test')
14
+
15
+ db.strict = true
16
+
17
+ begin
18
+ # Can't reference collection that does not exist
19
+ db.collection('does-not-exist')
20
+ puts "error: expected exception"
21
+ rescue => ex
22
+ puts "expected exception: #{ex}"
23
+ end
24
+
25
+ begin
26
+ # Can't create collection that already exists
27
+ db.create_collection('test')
28
+ puts "error: expected exception"
29
+ rescue => ex
30
+ puts "expected exception: #{ex}"
31
+ end
32
+
33
+ db.strict = false
34
+ db.drop_collection('test')
@@ -0,0 +1,35 @@
1
+ $LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
2
+ require 'mongo'
3
+ require 'pp'
4
+
5
+ include Mongo
6
+
7
+ host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
8
+ port = ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT
9
+
10
+ puts "Connecting to #{host}:#{port}"
11
+ db = Connection.new(host, port).db('ruby-mongo-examples')
12
+ coll = db.collection('test')
13
+
14
+ # Remove all records, if any
15
+ coll.clear
16
+
17
+ # Insert record with all sorts of values
18
+ coll.insert('array' => [1, 2, 3],
19
+ 'string' => 'hello',
20
+ 'hash' => {'a' => 1, 'b' => 2},
21
+ 'date' => Time.now, # milliseconds only; microseconds are not stored
22
+ 'oid' => ObjectID.new,
23
+ 'binary' => Binary.new([1, 2, 3]),
24
+ 'int' => 42,
25
+ 'float' => 33.33333,
26
+ 'regex' => /foobar/i,
27
+ 'boolean' => true,
28
+ 'where' => Code.new('this.x == 3'),
29
+ 'dbref' => DBRef.new(coll.name, ObjectID.new),
30
+ 'null' => nil,
31
+ 'symbol' => :zildjian)
32
+
33
+ pp coll.find().next_object
34
+
35
+ coll.clear
@@ -2,11 +2,18 @@ require 'mongo/types/binary'
2
2
  require 'mongo/types/dbref'
3
3
  require 'mongo/types/objectid'
4
4
  require 'mongo/types/regexp_of_holding'
5
- require 'mongo/types/undefined'
6
5
 
7
- require 'mongo/mongo'
6
+ require 'mongo/errors'
7
+ require 'mongo/connection'
8
8
  require 'mongo/message'
9
9
  require 'mongo/db'
10
10
  require 'mongo/cursor'
11
11
  require 'mongo/collection'
12
12
  require 'mongo/admin'
13
+
14
+ module Mongo
15
+ ASCENDING = 1
16
+ DESCENDING = -1
17
+
18
+ VERSION = "0.15"
19
+ end
@@ -1,86 +1,83 @@
1
1
  # --
2
2
  # Copyright (C) 2008-2009 10gen Inc.
3
3
  #
4
- # This program is free software: you can redistribute it and/or modify it
5
- # under the terms of the GNU Affero General Public License, version 3, as
6
- # published by the Free Software Foundation.
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
7
  #
8
- # This program is distributed in the hope that it will be useful, but WITHOUT
9
- # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
- # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
11
- # for more details.
8
+ # http://www.apache.org/licenses/LICENSE-2.0
12
9
  #
13
- # You should have received a copy of the GNU Affero General Public License
14
- # along with this program. If not, see <http://www.gnu.org/licenses/>.
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
15
  # ++
16
16
 
17
17
  require 'mongo/util/ordered_hash'
18
18
 
19
- module XGen
20
- module Mongo
21
- module Driver
19
+ module Mongo
22
20
 
23
- # Provide administrative database methods: those having to do with
24
- # profiling and validation.
25
- class Admin
21
+ # Provide administrative database methods: those having to do with
22
+ # profiling and validation.
23
+ class Admin
26
24
 
27
- def initialize(db)
28
- @db = db
29
- end
30
-
31
- # Return the current database profiling level.
32
- def profiling_level
33
- oh = OrderedHash.new
34
- oh[:profile] = -1
35
- doc = @db.db_command(oh)
36
- raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc) && doc['was'].kind_of?(Numeric)
37
- case doc['was'].to_i
38
- when 0
39
- :off
40
- when 1
41
- :slow_only
42
- when 2
43
- :all
44
- else
45
- raise "Error: illegal profiling level value #{doc['was']}"
46
- end
47
- end
25
+ def initialize(db)
26
+ @db = db
27
+ end
48
28
 
49
- # Set database profiling level to :off, :slow_only, or :all.
50
- def profiling_level=(level)
51
- oh = OrderedHash.new
52
- oh[:profile] = case level
53
- when :off
54
- 0
55
- when :slow_only
56
- 1
57
- when :all
58
- 2
59
- else
60
- raise "Error: illegal profiling level value #{level}"
61
- end
62
- doc = @db.db_command(oh)
63
- raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc)
64
- end
29
+ # Return the current database profiling level.
30
+ def profiling_level
31
+ oh = OrderedHash.new
32
+ oh[:profile] = -1
33
+ doc = @db.db_command(oh)
34
+ raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc) && doc['was'].kind_of?(Numeric)
35
+ case doc['was'].to_i
36
+ when 0
37
+ :off
38
+ when 1
39
+ :slow_only
40
+ when 2
41
+ :all
42
+ else
43
+ raise "Error: illegal profiling level value #{doc['was']}"
44
+ end
45
+ end
65
46
 
66
- # Return an array contining current profiling information from the
67
- # database.
68
- def profiling_info
69
- @db.query(Collection.new(@db, DB::SYSTEM_PROFILE_COLLECTION), Query.new({})).to_a
70
- end
47
+ # Set database profiling level to :off, :slow_only, or :all.
48
+ def profiling_level=(level)
49
+ oh = OrderedHash.new
50
+ oh[:profile] = case level
51
+ when :off
52
+ 0
53
+ when :slow_only
54
+ 1
55
+ when :all
56
+ 2
57
+ else
58
+ raise "Error: illegal profiling level value #{level}"
59
+ end
60
+ doc = @db.db_command(oh)
61
+ raise "Error with profile command: #{doc.inspect}" unless @db.ok?(doc)
62
+ end
71
63
 
72
- # Validate a named collection by raising an exception if there is a
73
- # problem or returning +true+ if all is well.
74
- def validate_collection(name)
75
- doc = @db.db_command(:validate => name)
76
- raise "Error with validate command: #{doc.inspect}" unless @db.ok?(doc)
77
- result = doc['result']
78
- raise "Error with validation data: #{doc.inspect}" unless result.kind_of?(String)
79
- raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i
80
- true
81
- end
64
+ # Return an array contining current profiling information from the
65
+ # database.
66
+ def profiling_info
67
+ @db.query(Collection.new(@db, DB::SYSTEM_PROFILE_COLLECTION), Query.new({})).to_a
68
+ end
82
69
 
83
- end
70
+ # Validate a named collection by raising an exception if there is a
71
+ # problem or returning an interesting hash (see especially the
72
+ # 'result' string value) if all is well.
73
+ def validate_collection(name)
74
+ doc = @db.db_command(:validate => name)
75
+ raise "Error with validate command: #{doc.inspect}" unless @db.ok?(doc)
76
+ result = doc['result']
77
+ raise "Error with validation data: #{doc.inspect}" unless result.kind_of?(String)
78
+ raise "Error: invalid collection #{name}: #{doc.inspect}" if result =~ /\b(exception|corrupt)\b/i
79
+ doc
84
80
  end
81
+
85
82
  end
86
83
  end