<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:38: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-2267] Continue  run FindOneAndUpdate to get sequence ,but not inc, still the first result</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-2267</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;type Sequence struct &lt;/p&gt;
{
&#160; &#160; Id &#160; &#160; &#160; primitive.ObjectID `json:&quot;id&quot; &#160; form:&quot;id&quot; &#160;bson:&quot;_id&quot;`
&#160; &#160; Field &#160; &#160;string &#160; &#160; &#160; &#160; &#160; &#160; `json:&quot;field&quot; form:&quot;field&quot; bson:&quot;field&quot;`
&#160; &#160; Sequence int64 &#160; &#160; &#160; &#160; &#160; &#160; &#160;`json:&quot;sequence&quot; form:&quot;sequence&quot; bson:&quot;sequence&quot;`
}
&lt;p&gt;&#160;&lt;br/&gt;
func (model *Sequence) GetNextSequence(field string) (int64, error) &lt;/p&gt;
{
&#160; &#160; err := util.C(model).FindOneAndUpdate(context.TODO(),
&#160; &#160; &#160; &#160; bson.M\{&quot;field&quot;: &quot;Account.Number&quot;}
&lt;p&gt;, bson.M{&quot;$inc&quot;: bson.M{&quot;sequence&quot;: 1}},&lt;br/&gt;
&#160; &#160; &#160; &#160; options.FindOneAndUpdate().SetUpsert(true)).Decode(&amp;amp;model)&lt;br/&gt;
&#160; &#160; if err != nil &lt;/p&gt;
{
&#160; &#160; &#160; &#160; return -1, err
&#160; &#160; }
&lt;p&gt;&#160; &#160; return model.Sequence, nil&lt;br/&gt;
}&lt;br/&gt;
The first run func,can get correct result.Continue to run func&#160; ,but not inc, still the first result. What is the right thing to do&#65311;&lt;br/&gt;
Thanks&#12290;&lt;/p&gt;</description>
                <environment></environment>
        <key id="1960683">GODRIVER-2267</key>
            <summary>Continue  run FindOneAndUpdate to get sequence ,but not inc, still the first result</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="13203">Gone away</resolution>
                                        <assignee username="benji.rewis@mongodb.com">Benji Rewis</assignee>
                                    <reporter username="8080268@qq.com">oy h</reporter>
                        <labels>
                            <label>Bug</label>
                    </labels>
                <created>Mon, 10 Jan 2022 04:21:37 +0000</created>
                <updated>Fri, 27 Oct 2023 20:01:13 +0000</updated>
                            <resolved>Wed, 12 Jan 2022 02:37:59 +0000</resolved>
                                    <version>1.8.2</version>
                                                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4287376" author="benji.rewis" created="Wed, 12 Jan 2022 02:37:59 +0000"  >&lt;p&gt;No worries. Feel free to comment on this ticket or open another if you have another issue.&lt;/p&gt;</comment>
                            <comment id="4287222" author="JIRAUSER1264297" created="Wed, 12 Jan 2022 00:04:14 +0000"  >&lt;p&gt;Sorry, I didn&apos;t turn off the vscode test cache.&#160;FindOneAndUpdate is right&#12290;Thanks for your help&#12290;&lt;/p&gt;</comment>
                            <comment id="4286034" author="benji.rewis" created="Tue, 11 Jan 2022 16:37:07 +0000"  >&lt;p&gt;Hello again, &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=8080268%40qq.com&quot; class=&quot;user-hover&quot; rel=&quot;8080268@qq.com&quot;&gt;8080268@qq.com&lt;/a&gt;! I believe what you&apos;re saying is that it&apos;s surprising that when you run &lt;tt&gt;FindOneAndUpdate&lt;/tt&gt; with a &lt;tt&gt;$inc&lt;/tt&gt; stage, the returned document does not show the increment that has been executed. &lt;a href=&quot;https://github.com/mongodb/mongo-go-driver/blob/master/mongo/collection.go#L1485-L1486&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;By default&lt;/a&gt;, &lt;tt&gt;FindOneAndUpdate&lt;/tt&gt; will return the document it found before it has been potentially updated. You&apos;d have to use &lt;tt&gt;SetReturnDocument&lt;/tt&gt; with a value of &lt;tt&gt;options.After&lt;/tt&gt; to specify that you&apos;d like the updated document to be the one returned. I&apos;ve attached some example code similar to the code you&apos;ve provided that shows how you might do so. Let me know if this is helpful.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;nobr&quot;&gt;&lt;a href=&quot;https://jira.mongodb.org/secure/attachment/354374/354374_inc.go&quot; title=&quot;inc.go attached to GODRIVER-2267&quot;&gt;inc.go&lt;sup&gt;&lt;img class=&quot;rendericon&quot; src=&quot;https://jira.mongodb.org/images/icons/link_attachment_7.gif&quot; height=&quot;7&quot; width=&quot;7&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/sup&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</comment>
                            <comment id="4284293" author="benji.rewis" created="Mon, 10 Jan 2022 21:26:42 +0000"  >&lt;p&gt;Hello &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=8080268%40qq.com&quot; class=&quot;user-hover&quot; rel=&quot;8080268@qq.com&quot;&gt;8080268@qq.com&lt;/a&gt;! Thanks for your bug report; we&apos;re taking a look now.&lt;/p&gt;</comment>
                            <comment id="4282433" author="JIRAUSER1264297" created="Mon, 10 Jan 2022 04:27:30 +0000"  >&lt;p&gt;If drop Sequence collection ,then run func, return err &quot;Get failed mongo: no documents in result &quot;. &lt;/p&gt;

&lt;p&gt;But db had document.&lt;/p&gt;

{\{ &quot;_id&quot; : ObjectId(&quot;61dbb4cd3da10a3250f8a75f&quot;), &quot;field&quot; : &quot;Account.Number&quot;, &quot;sequence&quot; : 1}</comment>
                    </comments>
                    <attachments>
                            <attachment id="354374" name="inc.go" size="1255" author="benji.rewis@mongodb.com" created="Tue, 11 Jan 2022 16:37:14 +0000"/>
                    </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|hzzgcf:</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>