<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 22:00:16 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CXX-769] GridFS chunk retrieval</title>
                <link>https://jira.mongodb.org/browse/CXX-769</link>
                <project id="11980" key="CXX">C++ Driver</project>
                    <description>&lt;p&gt;To retrieve a chunk from GridFS using the C++ legacy driver I need at minimum the following code:&lt;/p&gt;
&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;GridFS gfs(client, &quot;test&quot;, &quot;db&quot;); // 2x createIndex()  &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;GridFile file = gfs.findFile(filename); // 1x findOne&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;GridFSChunk chunk = file.getChunk(); // 1x findOne&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;
&lt;p&gt;This has quite some overhead (3 extra queries) if I already have a client connection and know which chunk to retrieve.&lt;/p&gt;

&lt;p&gt;Is there a way (except for writing my own custom query) to retrieve one chunk by performing only one Mongo query? &lt;/p&gt;

&lt;p&gt;Can you explain me why the createIndex calls are necessary in the GridFS constructor?&lt;/p&gt;</description>
                <environment></environment>
        <key id="242955">CXX-769</key>
            <summary>GridFS chunk retrieval</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="-1">Unassigned</assignee>
                                    <reporter username="joostmeijles">Joost Meijles</reporter>
                        <labels>
                            <label>legacy-cxx</label>
                    </labels>
                <created>Wed, 9 Dec 2015 13:57:08 +0000</created>
                <updated>Wed, 11 Sep 2019 19:05:57 +0000</updated>
                            <resolved>Tue, 22 Dec 2015 15:33:48 +0000</resolved>
                                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="1120484" author="samantha.ritter@10gen.com" created="Tue, 22 Dec 2015 15:33:35 +0000"  >&lt;p&gt;Thanks Joost, I&apos;m going to close this ticket.  Feel free to open a new one if you have any other questions.&lt;/p&gt;</comment>
                            <comment id="1120201" author="joostmeijles" created="Tue, 22 Dec 2015 07:21:48 +0000"  >&lt;p&gt;Hi Samantha,&lt;/p&gt;

&lt;p&gt;Thanks for the clarification, that completely answers my question. &lt;/p&gt;</comment>
                            <comment id="1118445" author="samantha.ritter@10gen.com" created="Fri, 18 Dec 2015 19:19:48 +0000"  >&lt;p&gt;Hi Joost,&lt;/p&gt;

&lt;p&gt;Correct, there is still a race.  The GridFS protocol is inherently race-y, and will be until mongod supports some sort of atomic document access across collections.  Running findFile() directly before you retrieve a chunk just makes that window smaller.  If you&apos;re planning to access the underlying collections directly then eh, it&apos;s up to you!&lt;/p&gt;

&lt;p&gt;We only check for those indexes once, when the GridFS object is constructed.  The object&apos;s construction itself is unrelated to either insertion or retrieval.  The most efficient thing to do is create a GridFS object in your application and keep it around to use for all of your grid operations.  Then, those two extra network calls only happen once.  Because the indexes are on two different collections, there is no way to check for them with fewer than two network roundtrips.  So, unfortunately, no plans to optimize that.&lt;/p&gt;</comment>
                            <comment id="1117941" author="joostmeijles" created="Fri, 18 Dec 2015 08:04:40 +0000"  >&lt;p&gt;Hi Samantha,&lt;/p&gt;

&lt;p&gt;Thanks for your reply.&lt;/p&gt;

&lt;p&gt;&amp;gt; The reason the driver&apos;s gridfs class forces you to call findFile() before getChunk() is to reduce the chance of a race condition with another client.&lt;br/&gt;
Clear, but as this does not fully eliminate the possibility of a race condition I still have to handle the exception that could be raised. So I don&apos;t see the advantage of doing a findFile() when I already know the file id. &lt;br/&gt;
Is this correct?&lt;/p&gt;

&lt;p&gt;&amp;gt; In order to work efficiently, gridfs needs two indexes, one on the &quot;files&quot; collection and one on the &quot;chunks&quot; collection.&lt;br/&gt;
I would expect to check this only upon insertion and not also on retrieval. &lt;br/&gt;
Are there plans to optimize this?&lt;/p&gt;</comment>
                            <comment id="1117477" author="samantha.ritter@10gen.com" created="Thu, 17 Dec 2015 19:47:29 +0000"  >&lt;p&gt;Hi there,&lt;/p&gt;

&lt;p&gt;It is possible for you to query the gridfs&apos;s underlying collection directly, though we don&apos;t recommend doing so.  If you already knew the file id, collection prefix (yours is &quot;db&quot;) and the chunk number you could simply run a findOne on &quot;db.chunks&quot; for a document with the right file id and chunk number.&lt;/p&gt;

&lt;p&gt;The reason the driver&apos;s gridfs class forces you to call findFile() before getChunk() is to reduce the chance of a race condition with another client.  For example, say you stored &quot;file.txt&quot; in gridfs, and kept track of the chunk number of some chunk to use later.  In the meantime, another client calls removeFile() on the same database, which removes all of &quot;file.txt&quot;&apos;s chunks.  If you later went to read the chunk without first calling findFile(), you would fail to find the chunk.&lt;/p&gt;

&lt;p&gt;In order to work efficiently, gridfs needs two indexes, one on the &quot;files&quot; collection and one on the &quot;chunks&quot; collection.  If those indexes already exist, then calling createIndex() will have no effect, it won&apos;t do unnecessary work.  It will still add a network roundtrip, but a newly-constructed gridfs object has no way of knowing whether those indexes have been created without asking the server.&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrdsbz:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>9223372036854775807</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                    <customfield id="customfield_10557" key="com.pyxis.greenhopper.jira:gh-sprint">
                        <customfieldname>Sprint</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue id="801">Platforms E (01/08/16)</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>