<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:35:11 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-889] How to Collection.UpdateOne using the result of bson.Marshal?</title>
                <link>https://jira.mongodb.org/browse/GODRIVER-889</link>
                <project id="14289" key="GODRIVER">Go Driver</project>
                    <description>&lt;p&gt;For example I have struct like this:&lt;/p&gt;

&lt;p&gt;type Profile struct &lt;/p&gt;
{
 Vip uint32
 Lvl uint32
 Heros Heros
}

&lt;p&gt;type Heros struct &lt;/p&gt;
{
 HeroIds []uint32 `bson:&quot;hids&quot;`
 HeroSkills []HeroSkill `bson:&quot;hskls&quot;`
}

&lt;p&gt;type HeroSkill struct &lt;/p&gt;
{
 CounterSkill []string
 PassiveSkill []string
 TriggerSkill []string
}

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

&lt;p&gt;than, I want to set a record to collection using UpdateOne.&lt;/p&gt;

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

&lt;p&gt;id := &quot;alsdkfj&quot;&lt;br/&gt;
collection := db.Collection(&quot;profiles&quot;)&lt;/p&gt;

&lt;p&gt;heros := Heros&lt;/p&gt;
{
 HeroIds: []uint32\{1, 2, 3}
&lt;p&gt;,&lt;br/&gt;
}&lt;br/&gt;
bsb, err := bson.Marshal(heros)&lt;br/&gt;
if err != nil &lt;/p&gt;
{
 log.Fatal(&quot;bson marshal err&quot;, err)
 return
}
&lt;p&gt;update := bsonx.Doc{&lt;br/&gt;
 {&quot;$set&quot;, bsonx.Document(bsonx.Doc{{&quot;Vip&quot;, bsonx.Int32(3)}})},&lt;br/&gt;
 {&quot;$set&quot;, bsonx.Document(bsonx.Doc{{&quot;Level&quot;, bsonx.Int32(10)}})},&lt;br/&gt;
 {&quot;$set&quot;, bsonx.Document(bsonx.Doc{{&quot;Heros&quot;, bsb}})}, // this not work&lt;br/&gt;
}&lt;br/&gt;
res, err := collection.UpdateOne(ctx, bson.D{{&quot;_id&quot;, id}}, update, options.Update().SetUpsert(true))&lt;/p&gt;

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

&lt;p&gt;I don&apos;t find any way to transform []byte to bsonx.Val, so can put the result of bson.Marshal to bsonx.Doc.&lt;/p&gt;

&lt;p&gt;If I want to update&#160;complex construction conveniently&#65292;how should I do&#65311;&lt;/p&gt;

&lt;p&gt;Please help me, thanks!&lt;/p&gt;</description>
                <environment></environment>
        <key id="719765">GODRIVER-889</key>
            <summary>How to Collection.UpdateOne using the result of bson.Marshal?</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="zhangzhen">zhangzhen</reporter>
                        <labels>
                            <label>feature</label>
                    </labels>
                <created>Wed, 20 Mar 2019 04:26:43 +0000</created>
                <updated>Wed, 11 Sep 2019 18:35:11 +0000</updated>
                            <resolved>Thu, 21 Mar 2019 20:14:23 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="2187916" author="ian@10gen.com" created="Thu, 21 Mar 2019 20:14:23 +0000"  >&lt;p&gt;Hey &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=zhangzhen&quot; class=&quot;user-hover&quot; rel=&quot;zhangzhen&quot;&gt;zhangzhen&lt;/a&gt;, you should be using bson.D rather than bsonx.Doc - that way you don&apos;t have to marshal yourself.&lt;/p&gt;</comment>
                            <comment id="2185874" author="zhangzhen" created="Wed, 20 Mar 2019 06:12:54 +0000"  >&lt;p&gt;I use mongo golang sdk,&#160;&lt;a href=&quot;https://github.com/mongodb/mongo-go-driver&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-go-driver&lt;/a&gt;&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|hugwyf:</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>