-
Notifications
You must be signed in to change notification settings - Fork 532
-
Hi,
I'm currently learning to use MongoDB, using Ruby, and found some inconsistent detail.
The official Mongo Documentation for Ruby tells to use find_one() to find files.
in contrast, lib/mongo/grid/fs_bucket.rb tells
# @deprecated Please use #find instead with a limit of -1.
# Will be removed in version 3.0.
for find_one.
find() does return a list of meta documents describing the file, but there is no documented way to read the file contents when you have the meta document only.
Of course, it could be possible to use chunks = chunks_collection.find(:files_id => file_info[:_id]).sort(:n => 1) like the deprecated find_one did, but that's internals, and an API user should usually never use internals the documentation doesn't tell him to use, and it might be deprecated for reasons, so possible could be changed.
So what is the recommended, clean, and reliable way to get the file contents after calling find() ?
regards
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
Hello @hadmut. The find_one
method for the Ruby driver's implementation of GridFS has been deprecated for a very long time (since 2016!), and it is definitely an oversight that our official docs still recommend that approach.
The officially sanctioned way of getting at file data, which is supported by all of the official driver implementations, is to first query for the file using find
, and then using one of the download methods (e.g. open_download_stream
, download_to_stream
, open_download_stream_by_name
, and download_to_stream_by_name
).
This two-step process is definitely not as convenient as what the older find_one
method offered, though. We'll consider what we can do to improve that experience. Hopefully this answers your question, though.
Beta Was this translation helpful? Give feedback.