<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:37:12 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>[GODRIVER-1823] I need a updateAndReturnResult that is atomic</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-1823</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;Currently I am needing to do this:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;2148 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // start host modification atomicity&lt;/p&gt;

&lt;p&gt;2149 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // that is required because the host outsideIp may be updated twice once before the change and once after&lt;/p&gt;

&lt;p&gt;2150 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // yet before the read for checking if the IP changed&lt;/p&gt;

&lt;p&gt;2151&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;2152 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; updateResult, err := collection.UpdateOne(context.TODO(), filter, update)&lt;/p&gt;

&lt;p&gt;2153 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if err != nil &lt;/p&gt;
{

2154 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; _ = updateResult

2155 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; fmt.Printf(&quot;\n\nerror in wss config request when updating host: %s\n&quot;, err)

2156 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }

&lt;p&gt;2157&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;2158 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; //fmt.Printf(&quot;Matched %v documents and updated %v documents.\n&quot;, updateResult.MatchedCount, updateResult.ModifiedCount)&lt;/p&gt;

&lt;p&gt;2159&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;2160 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // compare this_host.OutsideIp and the update result.outsideIp to see if a new entry was added&lt;/p&gt;

&lt;p&gt;2161 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // if an entry was added, increment the host document&apos;s outsideIpChangesPerDay field&lt;/p&gt;

&lt;p&gt;2162 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; var updated_host Host&lt;/p&gt;

&lt;p&gt;2163 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; err = collection.FindOne(context.TODO(), filter).Decode(&amp;amp;updated_host)&lt;/p&gt;

&lt;p&gt;2164&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;2165 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; fmt.Printf(&quot;this_host.outsideIp: \t%+v\nupdated_host.outsideIp: \t%v\n\n&quot;, this_host.OutsideIp, updated_host.OutsideIp);&lt;/p&gt;

&lt;p&gt;2166&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;2167 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (updated_host.OutsideIp&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt; != this_host.OutsideIp&lt;span class=&quot;error&quot;&gt;&amp;#91;0&amp;#93;&lt;/span&gt;) &lt;/p&gt;
{

2168&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;

2169 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // increment outsideIpChangesPerDay

2170&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;

2171 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }

&lt;p&gt;2172&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160;&lt;/p&gt;

&lt;p&gt;2173 &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; // end host modification atomicity&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;If line 2152 (collection.UpdateOne) returned the updated document with regards to not allowing another update before returning (ie atomic) then I would not have to start and end atomicity on the routine...&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</description>
                <environment>Linux</environment>
        <key id="1583301">GODRIVER-1823</key>
            <summary>I need a updateAndReturnResult that is atomic</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</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="13202">Works as Designed</resolution>
                                        <assignee username="kevin.albertson@mongodb.com">Kevin Albertson</assignee>
                                    <reporter username="andrewhodel@gmail.com">Andrew Hodel</reporter>
                        <labels>
                    </labels>
                <created>Thu, 7 Jan 2021 17:35:59 +0000</created>
                <updated>Fri, 27 Oct 2023 13:16:25 +0000</updated>
                            <resolved>Tue, 19 Jan 2021 14:03:52 +0000</resolved>
                                    <version>1.4.4</version>
                                                    <component>API</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="3573958" author="JIRAUSER1251601" created="Wed, 20 Jan 2021 17:31:33 +0000"  >&lt;p&gt;This is difficult to find in the documentation.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Here&apos;s how you actually write it:&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&amp;lt;code&amp;gt;&lt;/p&gt;

&lt;p&gt;&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; var updated_host Host&lt;/p&gt;

&lt;p&gt;&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; after := options.After&lt;/p&gt;

&lt;p&gt;&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; opt := options.FindOneAndUpdateOptions&lt;/p&gt;
{

&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; ReturnDocument: &amp;amp;after,

&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }

&lt;p&gt;&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; updateFindErr := collection.FindOneAndUpdate(context.TODO(), filter, update, &amp;amp;opt).Decode(&amp;amp;updated_host)&lt;/p&gt;

&lt;p&gt;&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; if (updateFindErr != nil) &lt;/p&gt;
{

&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; fmt.Printf(&quot;error with FindOneAndUpdate: %s\n&quot;, updateFindErr)

&#160;&#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; }

&lt;p&gt;&amp;lt;/code&amp;gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Here are the 5 urls of documentation and examples you have to read to understand it because it is not written out in the documentation for FindOneAndUpdate()&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.FindOneAndUpdate&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.FindOneAndUpdate&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.4.5/mongo/options#FindOneAndUpdateOptions&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.4.5/mongo/options#FindOneAndUpdateOptions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.4.5/mongo/options#ReturnDocument&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://pkg.go.dev/go.mongodb.org/mongo-driver@v1.4.5/mongo/options#ReturnDocument&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/blob/v1.4.5/mongo/options/mongooptions.go#L83&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver/blob/v1.4.5/mongo/options/mongooptions.go#L83&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/cgiacomi/go-mongo-examples/blob/master/main.go&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/cgiacomi/go-mongo-examples/blob/master/main.go&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="3570243" author="kevin.albertson" created="Tue, 19 Jan 2021 02:47:06 +0000"  >&lt;p&gt;Hello &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=andrewhodel%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;andrewhodel@gmail.com&quot;&gt;andrewhodel@gmail.com&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;If I am understanding correctly, you need an atomic find and update to ensure no changes occur between the UpdateOne and FindOne operations in the example provided. The &lt;a href=&quot;https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Collection.FindOneAndUpdate&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;findOneAndUpdate&lt;/a&gt; may suffice. It uses the underlying &lt;tt&gt;findAndModify&lt;/tt&gt; command, which has atomicity guarantees when operating on one document (&lt;a href=&quot;https://docs.mongodb.com/manual/reference/command/findAndModify/#comparisons-with-the-update-method&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;reference&lt;/a&gt;). It can optionally return the document before or after the update based on the &lt;tt&gt;ReturnDocument&lt;/tt&gt; option.&lt;/p&gt;

&lt;p&gt;Since this isn&apos;t a bug or feature request we&apos;re closing the issue. For further assistance please create a post in our community forum &lt;a href=&quot;https://developer.mongodb.com/community/forums/tag/golang&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
Kevin&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|hya4nr:</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>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>