mongodb-mongo 0.6.2 → 0.6.3

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 (40) hide show
  1. data/README.rdoc +11 -10
  2. data/bin/run_test_script +1 -1
  3. data/bin/standard_benchmark +82 -23
  4. data/examples/info.rb +1 -1
  5. data/examples/queries.rb +1 -1
  6. data/lib/mongo/admin.rb +9 -9
  7. data/lib/mongo/collection.rb +16 -15
  8. data/lib/mongo/cursor.rb +9 -9
  9. data/lib/mongo/db.rb +36 -18
  10. data/lib/mongo/gridfs/chunk.rb +16 -0
  11. data/lib/mongo/gridfs/grid_store.rb +28 -5
  12. data/lib/mongo/gridfs.rb +15 -0
  13. data/lib/mongo/message/get_more_message.rb +16 -0
  14. data/lib/mongo/message/insert_message.rb +16 -0
  15. data/lib/mongo/message/kill_cursors_message.rb +16 -0
  16. data/lib/mongo/message/message.rb +16 -0
  17. data/lib/mongo/message/message_header.rb +16 -0
  18. data/lib/mongo/message/msg_message.rb +16 -0
  19. data/lib/mongo/message/opcodes.rb +16 -0
  20. data/lib/mongo/message/query_message.rb +16 -0
  21. data/lib/mongo/message/remove_message.rb +16 -0
  22. data/lib/mongo/message/update_message.rb +16 -0
  23. data/lib/mongo/message.rb +16 -0
  24. data/lib/mongo/mongo.rb +9 -9
  25. data/lib/mongo/query.rb +9 -9
  26. data/lib/mongo/types/binary.rb +9 -9
  27. data/lib/mongo/types/dbref.rb +9 -9
  28. data/lib/mongo/types/objectid.rb +9 -9
  29. data/lib/mongo/types/regexp_of_holding.rb +9 -9
  30. data/lib/mongo/types/undefined.rb +9 -9
  31. data/lib/mongo/util/byte_buffer.rb +9 -9
  32. data/lib/mongo/util/ordered_hash.rb +9 -9
  33. data/lib/mongo/util/xml_to_ruby.rb +9 -9
  34. data/lib/mongo.rb +7 -0
  35. data/mongo-ruby-driver.gemspec +3 -3
  36. data/tests/mongo-qa/indices +5 -2
  37. data/tests/test_bson.rb +6 -3
  38. data/tests/test_db_api.rb +11 -11
  39. data/tests/test_grid_store.rb +19 -2
  40. metadata +2 -2
data/README.rdoc CHANGED
@@ -315,16 +315,17 @@ Adrian Madrid, aemadrid@gmail.com
315
315
 
316
316
  = License
317
317
 
318
- Copyright (C) 2008-2009 10gen Inc.
318
+ Copyright 2008-2009 10gen Inc.
319
319
 
320
- This program is free software: you can redistribute it and/or modify it under
321
- the terms of the GNU Affero General Public License, version 3, as published by
322
- the Free Software Foundation.
320
+ Licensed under the Apache License, Version 2.0 (the "License");
321
+ you may not use this file except in compliance with the License.
322
+ You may obtain a copy of the License at
323
323
 
324
- This program is distributed in the hope that it will be useful, but WITHOUT
325
- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
326
- FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
327
- details.
324
+ http://www.apache.org/licenses/LICENSE-2.0
325
+
326
+ Unless required by applicable law or agreed to in writing, software
327
+ distributed under the License is distributed on an "AS IS" BASIS,
328
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
329
+ See the License for the specific language governing permissions and
330
+ limitations under the License.
328
331
 
329
- See http://www.gnu.org/licenses for a copy of the GNU Affero General Public
330
- License.
data/bin/run_test_script CHANGED
@@ -10,7 +10,7 @@ if [ ! -f $HERE/../tests/mongo-qa/$1 ] ; then
10
10
  fi
11
11
 
12
12
  begintime=`date`
13
- ruby $HERE/../tests/mongo-qa/$1 >> $2
13
+ ruby $HERE/../tests/mongo-qa/$1 $3 $4 >> $2
14
14
  exitval=$?
15
15
  endtime=`date`
16
16
 
@@ -7,19 +7,46 @@ require 'mongo'
7
7
 
8
8
  include XGen::Mongo::Driver
9
9
 
10
- N = 30_000
10
+ TRIALS = 2
11
+ PER_TRIAL = 5000
12
+ BATCH_SIZE = 100
11
13
 
12
- def report(str, t0, t1, n)
13
- dt = t1.to_f - t0.to_f
14
- printf("%16s: %03.8f\n", str, dt)
14
+ SMALL = {}
15
+ MEDIUM = {
16
+ 'integer' => 5,
17
+ 'number' => 5.05,
18
+ 'boolean' => false,
19
+ 'array' => ['test', 'benchmark']
20
+ }
21
+ LARGE = {
22
+ 'base_url' => 'http://www.example.com/test-me',
23
+ 'total_word_count' => 6743,
24
+ 'access_time' => Time.now,
25
+ 'meta_tags' => {
26
+ 'description' => 'i am a long description string',
27
+ 'author' => 'Holly Man',
28
+ 'dynamically_created_meta_tag' => 'who know\n what'
29
+ },
30
+ 'page_structure' => {
31
+ 'counted_tags' => 3450,
32
+ 'no_of_js_attached' => 10,
33
+ 'no_of_images' => 6
34
+ },
35
+ 'harvested_words' => ['10gen','web','open','source','application','paas',
36
+ 'platform-as-a-service','technology','helps',
37
+ 'developers','focus','building','mongodb','mongo'] * 20
38
+ }
39
+
40
+ def report(str, t)
41
+ printf("%s%d\n", str.ljust(60, '.'), PER_TRIAL / t)
15
42
  end
16
43
 
17
- def benchmark(str, n, db, after_proc=nil)
18
- coll = db.collection('benchmark')
44
+ def benchmark(str, proc, n, db, coll_name, object, setup=nil)
45
+ coll = db.collection(coll_name)
46
+ setup.call(coll, object) if setup
19
47
  t0 = Time.new
20
- n.times { |i| yield coll, i }
21
- after_proc.call if after_proc
22
- report(str, t0, Time.new, n)
48
+ n.times { |i| proc.call(coll, object, i) }
49
+ report(str, Time.new.to_f - t0.to_f)
23
50
  end
24
51
 
25
52
  host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
@@ -27,23 +54,55 @@ port = ENV['MONGO_RUBY_DRIVER_PORT'] || XGen::Mongo::Driver::Mongo::DEFAULT_PORT
27
54
 
28
55
  db = Mongo.new(host, port).db('ruby-benchmark')
29
56
  db.drop_collection('benchmark')
30
- coll = db.collection('benchmark')
31
57
 
32
- coll.create_index('foo', 'i')
58
+ insert = Proc.new { |coll, object, i|
59
+ object['x'] = i
60
+ coll.insert(object)
61
+ }
62
+ benchmark('insert (small, no index)', insert, PER_TRIAL, db, 'small_none', SMALL)
63
+ benchmark('insert (medium, no index)', insert, PER_TRIAL, db, 'medium_none', MEDIUM)
64
+ benchmark('insert (large, no index)', insert, PER_TRIAL, db, 'large_none', LARGE)
33
65
 
34
- # Call to db.error forces inserts to finish
35
- benchmark('insert', N, db, Proc.new{db.error}) { |coll, i|
36
- coll.insert('i' => i)
66
+ index_on_x = Proc.new { |coll, object|
67
+ coll.create_index('foo', 'x') # TODO fix this in the driver!!
37
68
  }
38
- benchmark('find_first', N, db) { |coll, i|
39
- coll.find_first
69
+ benchmark('insert (small, indexed)', insert, PER_TRIAL, db, 'small_index', SMALL, index_on_x)
70
+ benchmark('insert (medium, indexed)', insert, PER_TRIAL, db, 'medium_index', MEDIUM, index_on_x)
71
+ benchmark('insert (large, indexed)', insert, PER_TRIAL, db, 'large_index', LARGE, index_on_x)
72
+
73
+ insert_batch = Proc.new { |coll, object, i|
74
+ object['x'] = i
75
+ coll.insert([object] * BATCH_SIZE)
40
76
  }
41
- benchmark('find', N, db) { |coll, i|
42
- coll.find('i' => 3).each { }
43
- coll.find('i' => 234).each { }
44
- coll.find('i' => 9876).each { }
77
+ benchmark('batch insert (small, no index)', insert_batch, PER_TRIAL/BATCH_SIZE, db, 'small_bulk', SMALL)
78
+ benchmark('batch insert (medium, no index)', insert_batch, PER_TRIAL/BATCH_SIZE, db, 'medium_bulk', MEDIUM)
79
+ benchmark('batch insert (large, no index)', insert_batch, PER_TRIAL/BATCH_SIZE, db, 'large_bulk', LARGE)
80
+
81
+ find_one = Proc.new { |coll, x, i|
82
+ coll.find_first('x' => x)
45
83
  }
46
- benchmark('find gt/lt', N, db) { |coll, i|
47
- h = {'i' => {'$gt' => 200, '$lt' => 200}}
48
- coll.find(h).each {}
84
+ benchmark('find_one (small, no index)', find_one, PER_TRIAL, db, 'small_none', PER_TRIAL / 2)
85
+ benchmark('find_one (medium, no index)', find_one, PER_TRIAL, db, 'medium_none', PER_TRIAL / 2)
86
+ benchmark('find_one (large, no index)', find_one, PER_TRIAL, db, 'large_none', PER_TRIAL / 2)
87
+
88
+ benchmark('find_one (small, indexed)', find_one, PER_TRIAL, db, 'small_index', PER_TRIAL / 2)
89
+ benchmark('find_one (medium, indexed)', find_one, PER_TRIAL, db, 'medium_index', PER_TRIAL / 2)
90
+ benchmark('find_one (large, indexed)', find_one, PER_TRIAL, db, 'large_index', PER_TRIAL / 2)
91
+
92
+ find = Proc.new { |coll, x, i|
93
+ coll.find('x' => x).each {}
49
94
  }
95
+ benchmark('find (small, no index)', find, PER_TRIAL, db, 'small_none', PER_TRIAL / 2)
96
+ benchmark('find (medium, no index)', find, PER_TRIAL, db, 'medium_none', PER_TRIAL / 2)
97
+ benchmark('find (large, no index)', find, PER_TRIAL, db, 'large_none', PER_TRIAL / 2)
98
+
99
+ benchmark('find (small, indexed)', find, PER_TRIAL, db, 'small_index', PER_TRIAL / 2)
100
+ benchmark('find (medium, indexed)', find, PER_TRIAL, db, 'medium_index', PER_TRIAL / 2)
101
+ benchmark('find (large, indexed)', find, PER_TRIAL, db, 'large_index', PER_TRIAL / 2)
102
+
103
+ benchmark('find range (small, indexed)', find, PER_TRIAL, db, 'small_index',
104
+ {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
105
+ benchmark('find range (medium, indexed)', find, PER_TRIAL, db, 'medium_index',
106
+ {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
107
+ benchmark('find range (large, indexed)', find, PER_TRIAL, db, 'large_index',
108
+ {"$gt" => PER_TRIAL / 2, "$lt" => PER_TRIAL / 2 + BATCH_SIZE})
data/examples/info.rb CHANGED
@@ -23,7 +23,7 @@ p db.collection_names
23
23
  p db.collections_info
24
24
 
25
25
  # Index information
26
- db.create_index('test', 'index_name', ['a'])
26
+ db.create_index('test', 'a')
27
27
  p db.index_information('test')
28
28
 
29
29
  # Destroy the collection
data/examples/queries.rb CHANGED
@@ -59,7 +59,7 @@ pp coll.find('a' => /[1|2]/).explain()
59
59
  # collection, in which case they will be used with all queries, or they can be
60
60
  # specified per query, in which case that hint overrides the hint associated
61
61
  # with the collection if any.
62
- coll.create_index('test_a_index', 'a')
62
+ coll.create_index('a')
63
63
  coll.hint = 'a'
64
64
 
65
65
  # You will see a different explanation now that the hint is in place
data/lib/mongo/admin.rb CHANGED
@@ -1,17 +1,17 @@
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'
@@ -1,17 +1,17 @@
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/query'
@@ -70,7 +70,7 @@ module XGen
70
70
  h = options.dup
71
71
  h[:limit] = 1
72
72
  cursor = find(selector, h)
73
- cursor.next_object # don't need to explicitly close b/c of limit
73
+ cursor.next_object # don't need to explicitly close b/c of limit
74
74
  end
75
75
 
76
76
  # Insert +objects+, which are hashes. "<<" is aliased to this method.
@@ -113,11 +113,12 @@ module XGen
113
113
  @db.modify_in_db(@name, selector, modifier_obj)
114
114
  end
115
115
 
116
- # Create a new index named +index_name+. +fields+ should be an array
117
- # of field names.
118
- def create_index(name, *fields)
119
- fields = *fields if fields.kind_of?(Array) && fields.length == 1
120
- @db.create_index(@name, name, fields)
116
+ # Create a new index. +field_or_spec+
117
+ # should be either a single field name or a Array of [field name,
118
+ # direction] pairs. Directions should be specified as
119
+ # XGen::Mongo::ASCENDING or XGen::Mongo::DESCENDING.
120
+ def create_index(field_or_spec)
121
+ @db.create_index(@name, field_or_spec)
121
122
  end
122
123
 
123
124
  # Drop index +name+.
data/lib/mongo/cursor.rb CHANGED
@@ -1,17 +1,17 @@
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/message'
data/lib/mongo/db.rb CHANGED
@@ -1,17 +1,17 @@
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 'socket'
@@ -305,7 +305,7 @@ module XGen
305
305
  def send_message(msg)
306
306
  send_to_db(MsgMessage.new(msg))
307
307
  end
308
-
308
+
309
309
  # Returns a Cursor over the query results.
310
310
  #
311
311
  # Note that the query gets sent lazily; the cursor calls
@@ -401,17 +401,28 @@ module XGen
401
401
  }
402
402
  end
403
403
 
404
- # Create a new index on +collection_name+ named +index_name+. +fields+
405
- # should be an array of field names. Normally called by
406
- # Collection#create_index.
407
- def create_index(collection_name, index_name, fields)
408
- sel = {:name => index_name, :ns => full_coll_name(collection_name)}
409
- field_h = {}
410
- fields.each { |f| field_h[f] = 1 }
411
- sel[:key] = field_h
404
+ # Create a new index on +collection_name+. +field_or_spec+
405
+ # should be either a single field name or a Array of [field name,
406
+ # direction] pairs. Directions should be specified as
407
+ # XGen::Mongo::ASCENDING or XGen::Mongo::DESCENDING. Normally called
408
+ # by Collection#create_index.
409
+ def create_index(collection_name, field_or_spec)
410
+ field_h = OrderedHash.new
411
+ if field_or_spec.is_a? String
412
+ field_h[field_or_spec] = 1
413
+ else
414
+ field_or_spec.each { |f| field_h[f[0]] = f[1] }
415
+ end
416
+ name = gen_index_name(field_h)
417
+ sel = {
418
+ :name => name,
419
+ :ns => full_coll_name(collection_name),
420
+ :key => field_h
421
+ }
412
422
  @semaphore.synchronize {
413
423
  send_to_db(InsertMessage.new(@name, SYSTEM_INDEX_COLLECTION, sel))
414
424
  }
425
+ name
415
426
  end
416
427
 
417
428
  # Insert +objects+ into +collection_name+. Normally called by
@@ -471,6 +482,13 @@ module XGen
471
482
  Digest::MD5.hexdigest("#{username}:mongo:#{plaintext}")
472
483
  end
473
484
 
485
+ def gen_index_name(spec)
486
+ temp = []
487
+ spec.each_pair { |field, direction|
488
+ temp = temp.push("#{field}_#{direction}")
489
+ }
490
+ return temp.join("_")
491
+ end
474
492
  end
475
493
  end
476
494
  end
@@ -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
  require 'mongo/types/objectid'
2
18
  require 'mongo/util/byte_buffer'
3
19
  require 'mongo/util/ordered_hash'
@@ -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
  require 'mongo/types/objectid'
2
18
  require 'mongo/util/ordered_hash'
3
19
  require 'mongo/gridfs/chunk'
@@ -27,7 +43,7 @@ module XGen
27
43
  # }
28
44
  class GridStore
29
45
 
30
- DEFAULT_ROOT_COLLECTION = 'gridfs'
46
+ DEFAULT_ROOT_COLLECTION = 'fs'
31
47
  DEFAULT_CONTENT_TYPE = 'text/plain'
32
48
 
33
49
  include Enumerable
@@ -51,6 +67,8 @@ module XGen
51
67
 
52
68
  attr_accessor :lineno
53
69
 
70
+ attr_reader :md5
71
+
54
72
  class << self
55
73
 
56
74
  def exist?(db, name, root_collection=DEFAULT_ROOT_COLLECTION)
@@ -126,6 +144,7 @@ module XGen
126
144
  @aliases = doc['aliases']
127
145
  @length = doc['length']
128
146
  @metadata = doc['metadata']
147
+ @md5 = doc['md5']
129
148
  else
130
149
  @files_id = XGen::Mongo::Driver::ObjectID.new
131
150
  @content_type = DEFAULT_CONTENT_TYPE
@@ -138,7 +157,7 @@ module XGen
138
157
  @curr_chunk = nth_chunk(0)
139
158
  @position = 0
140
159
  when 'w'
141
- chunk_collection.create_index("chunk_index", ['files_id', 'n'])
160
+ chunk_collection.create_index([['files_id', XGen::Mongo::ASCENDING], ['n', XGen::Mongo::ASCENDING]])
142
161
  delete_chunks
143
162
  @curr_chunk = Chunk.new(self, 'n' => 0)
144
163
  @content_type = options[:content_type] if options[:content_type]
@@ -146,7 +165,7 @@ module XGen
146
165
  @metadata = options[:metadata] if options[:metadata]
147
166
  @position = 0
148
167
  when 'w+'
149
- chunk_collection.create_index("chunk_index", ['files_id', 'n'])
168
+ chunk_collection.create_index([['files_id', XGen::Mongo::ASCENDING], ['n', XGen::Mongo::ASCENDING]])
150
169
  @curr_chunk = nth_chunk(last_chunk_number) || Chunk.new(self, 'n' => 0) # might be empty
151
170
  @curr_chunk.pos = @curr_chunk.data.length if @curr_chunk
152
171
  @metadata = options[:metadata] if options[:metadata]
@@ -354,7 +373,7 @@ module XGen
354
373
  when IO::SEEK_SET
355
374
  pos
356
375
  end
357
-
376
+
358
377
  new_chunk_number = (target_pos / @chunk_size).to_i
359
378
  if new_chunk_number != @curr_chunk.chunk_number
360
379
  @curr_chunk.save if @mode[0] == ?w
@@ -389,7 +408,7 @@ module XGen
389
408
  end
390
409
  @db = nil
391
410
  end
392
-
411
+
393
412
  def closed?
394
413
  @db == nil
395
414
  end
@@ -410,6 +429,10 @@ module XGen
410
429
  h['uploadDate'] = @upload_date
411
430
  h['aliases'] = @aliases
412
431
  h['metadata'] = @metadata
432
+ md5_command = OrderedHash.new
433
+ md5_command['filemd5'] = @files_id
434
+ md5_command['root'] = @root
435
+ h['md5'] = @db.db_command(md5_command)['md5']
413
436
  h
414
437
  end
415
438
 
data/lib/mongo/gridfs.rb CHANGED
@@ -1 +1,16 @@
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
+ # ++
1
16
  require 'mongo/gridfs/grid_store'
@@ -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
  require 'mongo/message/message'
2
18
  require 'mongo/message/opcodes'
3
19
 
@@ -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
  require 'mongo/message/message'
2
18
  require 'mongo/message/opcodes'
3
19
 
@@ -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
  require 'mongo/message/message'
2
18
  require 'mongo/message/opcodes'
3
19
 
@@ -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
  require 'mongo/util/bson'
2
18
  require 'mongo/util/byte_buffer'
3
19
 
@@ -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
  require 'mongo/util/byte_buffer'
2
18
 
3
19
  module XGen
@@ -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
  require 'mongo/message/message'
2
18
  require 'mongo/message/opcodes'
3
19