<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:59:23 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>[JAVA-3345] Get ID of last inserted document in a mongoDB w/ Java driver - WITH TYPED COLLECTION</title>
                <link>https://jira.mongodb.org/browse/JAVA-3345</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;For typed/generic collections, the @BsonId field is not recognized and changed by the driver. It seems impossible to get the object id of the last inserted document.&#160; For details, please see: &lt;a href=&quot;https://stackoverflow.com/questions/54362159/get-id-of-last-inserted-document-in-a-mongodb-w-java-driver-with-typed-collec&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://stackoverflow.com/questions/54362159/get-id-of-last-inserted-document-in-a-mongodb-w-java-driver-with-typed-collec&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I&apos;m asking this feature request because I did not get an answer for almost 6 months. I suppose that there is no good solution for this question other than changing the API. This change would probably be backwards compatible (I&apos;m not 100% sure though).&lt;/p&gt;</description>
                <environment></environment>
        <key id="828119">JAVA-3345</key>
            <summary>Get ID of last inserted document in a mongoDB w/ Java driver - WITH TYPED COLLECTION</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="3">Duplicate</resolution>
                                        <assignee username="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="nagylzs">Nagy L&#225;szl&#243; Zsolt</reporter>
                        <labels>
                    </labels>
                <created>Fri, 28 Jun 2019 17:16:48 +0000</created>
                <updated>Mon, 1 Jul 2019 12:19:22 +0000</updated>
                            <resolved>Mon, 1 Jul 2019 12:19:17 +0000</resolved>
                                                                    <component>Command Operations</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="2306527" author="ross@10gen.com" created="Mon, 1 Jul 2019 12:19:17 +0000"  >&lt;p&gt;Closing as a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-2674&quot; title=&quot;POJO ID property is not populated after insert&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-2674&quot;&gt;&lt;del&gt;JAVA-2674&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This feature was added in 3.10.   If you update your driver then you can take advantage of bug fixes and new features.&lt;/p&gt;

&lt;p&gt;All the best,&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="2306496" author="nagylzs" created="Mon, 1 Jul 2019 11:21:31 +0000"  >&lt;p&gt;We are using 3.6.1 driver, and it does not populate that field for me:&lt;/p&gt;

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

&lt;p&gt;&lt;tt&gt;&amp;lt;!-- &lt;a href=&quot;https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver&lt;/a&gt; --&amp;gt;&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;&amp;lt;dependency&amp;gt;&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;&#160; &amp;lt;groupId&amp;gt;org.mongodb&amp;lt;/groupId&amp;gt;&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;&#160; &amp;lt;artifactId&amp;gt;mongo-java-driver&amp;lt;/artifactId&amp;gt;&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;&#160; &amp;lt;version&amp;gt;3.6.1&amp;lt;/version&amp;gt;&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;&amp;lt;/dependency&amp;gt;&lt;/tt&gt;&lt;/p&gt;

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

&lt;p&gt;For this reason, we are still inserting documents instead of DTOs and we are reconstructing the DTO later. Here is an example:&lt;/p&gt;

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

&lt;p&gt;public ForumMessageDTO addMessage(Long instituteGroupId, Long userId, String message, Document data) {&#160;&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&#160; &#160; Document d = new Document();&lt;/tt&gt;&lt;br/&gt;
 &#160; &#160; &#160; &#160; &#160; d.put(&quot;instituteGroupId&quot;, instituteGroupId);&lt;br/&gt;
 &#160; &#160; &#160; &#160; &#160; &lt;tt&gt;d.put(&quot;userId&quot;, userId);&lt;/tt&gt;&lt;br/&gt;
 &lt;tt&gt;&#160; &#160;&#160;&lt;/tt&gt;&lt;tt&gt;d.put(&quot;created&quot;, new Date());&lt;/tt&gt;&lt;br/&gt;
 &#160; &#160; &#160; &#160; &#160; d.put(&quot;message&quot;, message);&lt;br/&gt;
 &lt;tt&gt;&#160; &#160; d.put(&quot;data&quot;, data);&lt;/tt&gt;&lt;br/&gt;
 &#160; &#160; &#160; &#160; &#160; &#160;messages.insertOne(d);&lt;br/&gt;
 &lt;tt&gt;&#160; &#160; ForumMessageDTO result = new ForumMessageDTO(instituteGroupId, userId, d.getDate(&quot;creted&quot;) , message, data);&lt;/tt&gt;&lt;br/&gt;
 &#160; &#160; &#160; &#160; &#160; result.setId(d.getObjectId(&quot;_id&quot;));&lt;br/&gt;
 &lt;tt&gt;&#160; &#160;return result;&lt;/tt&gt;&lt;br/&gt;
 }&lt;/p&gt;

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

&lt;p&gt;The declaration of the DTO starts with this:&lt;/p&gt;

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

&lt;p&gt;public class ForumMessageDTO { &lt;br/&gt;
 &#160; @Expose&lt;br/&gt;
 &#160; @BsonId&#160;&lt;br/&gt;
 &#160; private ObjectId id;&lt;br/&gt;
 &#160; public ObjectId getId() { public ObjectId getId()&lt;/p&gt;

{ return id; }

&lt;p&gt;&#160; public void setId(ObjectId id) { this.id = id; }&lt;/p&gt;

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

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

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

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

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

&lt;p&gt;&#160;&lt;/p&gt;</comment>
                            <comment id="2306390" author="ross@10gen.com" created="Mon, 1 Jul 2019 09:29:54 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=nagylzs&quot; class=&quot;user-hover&quot; rel=&quot;nagylzs&quot;&gt;nagylzs&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;This looks to be a duplicate of &lt;a href=&quot;https://jira.mongodb.org/browse/JAVA-2674&quot; title=&quot;POJO ID property is not populated after insert&quot; class=&quot;issue-link&quot; data-issue-key=&quot;JAVA-2674&quot;&gt;&lt;del&gt;JAVA-2674&lt;/del&gt;&lt;/a&gt;. By default in 3.10  Pojos with an ObjectId _id field / @bsonId property will automatically generate and mutate the property on insertion.&lt;/p&gt;

&lt;p&gt;Ross&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10010">
                    <name>Duplicate</name>
                                            <outwardlinks description="duplicates">
                                        <issuelink>
            <issuekey id="463462">JAVA-2674</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <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|huykov:</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>