unique indexes for GridFS chunks collections

This commit is contained in:
Kyle Banker 2010-04-07 15:53:38 -04:00
parent cd32dabd52
commit fd43eca514
5 changed files with 34 additions and 10 deletions

26
HISTORY
View File

@ -3,22 +3,32 @@
* Collection#find_and_modify
* Collection#stats
* DB#stats
* Exception class adjustments:
* Mongo::InvalidObjectID moved to BSON::InvalidObjectID
* Mongo::InvalidDocument moved to BSON::InvalidDocument
* Mongo::InvalidStringEncoding moved to BSON::InvalidStringEncoding
* Mongo::InvalidName replaced by Mongo::InvalidNSName and BSON::InvalidKeyName
* BSON-related code extracted into two separate gems: bson and bson_ext (Chuck Remes).
* Extensions compile on Rubinius (Chuck Remes).
* Query :fields options allows for values of 0 to exclude fields (houdini, railsjedi).
* BSON::Binary constructor can now take a string, which will be packed into an array.
* GridFS
* Option to delete old versions of GridFileSystem entries.
* Filename is now optional for Grid#put.
* Option to write arbitrary attributes to a file: @grid.put(@data, :favorite_phrase => "blimey!")
* Indexes created on the chunks collection are now unique. If you have an existing chunks collection,
you may want to remove
* Removed the following deprecated items:
* GridStore class
* BSON-related code extracted into two separate gems: bson and bson_ext (thx to Chuck Remes).
* mongo_ext no longer exists.
* BSON::Binary constructor can now take a string, which will be packed into an array.
* Exception class adjustments:
* Mongo::InvalidObjectID moved to BSON::InvalidObjectID
* Mongo::InvalidDocument moved to BSON::InvalidDocument
* Mongo::InvalidStringEncoding moved to BSON::InvalidStringEncoding
* Mongo::InvalidName replaced by Mongo::InvalidNSName and BSON::InvalidKeyName
* BSON types are now namespaced under the BSON module. These types include:
* Binary
* ObjectID
* Code
* DBRef
* MinKey and MaxKey
* Extensions compile on Rubinius (Chuck Remes).
0.19.3 2010-4-5
* Minor fix for assert_valid_keys.

View File

@ -34,7 +34,7 @@ module Mongo
@chunks = @db["#{fs_name}.chunks"]
@fs_name = fs_name
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]])
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
end
# Store a file in the file store.

View File

@ -34,8 +34,10 @@ module Mongo
@chunks = @db["#{fs_name}.chunks"]
@fs_name = fs_name
@files.create_index([['filename', 1], ['uploadDate', -1]])
@default_query_opts = {:sort => [['filename', 1], ['uploadDate', -1]], :limit => 1}
@files.create_index([['filename', 1], ['uploadDate', -1]])
@chunks.create_index([['files_id', Mongo::ASCENDING], ['n', Mongo::ASCENDING]], :unique => true)
end
# Open a file for reading or writing. Note that the options for this method only apply

View File

@ -30,6 +30,14 @@ class GridFileSystemTest < Test::Unit::TestCase
assert_equal data.length, @chunks_data.length
end
should "have a unique index on chunks" do
assert @db['fs.chunks'].index_information['files_id_1_n_1']['unique']
end
should "have an index on filename" do
assert @db['fs.files'].index_information['filename_1_uploadDate_-1']
end
should "return an empty string if length is zero" do
data = @grid.open('sample.file', 'r') { |f| f.read(0) }
assert_equal '', data

View File

@ -27,6 +27,10 @@ class GridTest < Test::Unit::TestCase
assert_equal @data, data
end
should "have a unique index on chunks" do
assert @chunks.index_information['files_id_1_n_1']['unique']
end
should "store the filename" do
file = @grid.get(@id)
assert_equal 'sample', file.filename