Skip to content

Commit 0a65823

Browse files
committed
Fix GridFS initial query for documents:
- Negative limit values are invalid on 3.2 and higher. - Use a projection to only deserialize the _id field. - Don't convert to array - only need the first document.
1 parent a4f6519 commit 0a65823

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/mongo/grid/fs_bucket.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def files_name
438438
end
439439

440440
def ensure_indexes!
441-
if files_collection.find({}, limit: -1).to_a.empty?
441+
if files_collection.find({}, limit: 1, projection: { _id: 1 }).first.nil?
442442
chunks_collection.indexes.create_one(FSBucket::CHUNKS_INDEX, :unique => true)
443443
files_collection.indexes.create_one(FSBucket::FILES_INDEX)
444444
end

0 commit comments

Comments
 (0)