Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Inconsistency about GridFs #2870

hadmut started this conversation in General
Discussion options

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

You must be logged in to vote

Replies: 1 comment

Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /