<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:51:27 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-75] Generated ObjectID not unique </title>
                <link>https://jira.mongodb.org/browse/JAVA-75</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;In a test class the following code&lt;/p&gt;

&lt;p&gt; List&amp;lt;DBObject&amp;gt; users = new ArrayList&amp;lt;DBObject&amp;gt;();&lt;br/&gt;
 users.add(new BasicDBObject(userOne.toMap()));&lt;br/&gt;
 users.add(new BasicDBObject(userTwo.toMap()));&lt;br/&gt;
 users.add(new BasicDBObject(userThree.toMap()));&lt;br/&gt;
 repo.getCollection().insert(users);&lt;/p&gt;

&lt;p&gt;produce the same ObjectID for each userXXX inserted&lt;/p&gt;

&lt;p&gt;I see in the driver the &quot;algorithm&quot;:&lt;br/&gt;
private static int _nextInc = (new java.util.Random()).nextInt();&lt;br/&gt;
private static int _gentime = _flip( (int)(System.currentTimeMillis()/1000) );&lt;/p&gt;

&lt;p&gt;Suggestion:&lt;br/&gt;
With an &quot;algorithm&quot; like this :&lt;/p&gt;

&lt;p&gt;public static String calculateUniqueId() {&lt;br/&gt;
        long number = System.currentTimeMillis() * 1000 + (long) (Math.random() * 1000);&lt;br/&gt;
        return Long.toString(number, 25);&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;I have ids different for each userXXX in the same test where ObjectID fails &lt;/p&gt;
</description>
                <environment>MacOSX 10.6.2 JDK 1.6</environment>
        <key id="11087">JAVA-75</key>
            <summary>Generated ObjectID not unique </summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</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="5">Cannot Reproduce</resolution>
                                        <assignee username="eliot">Eliot Horowitz</assignee>
                                    <reporter username="desmax">Max Dess&#236;</reporter>
                        <labels>
                    </labels>
                <created>Wed, 6 Jan 2010 14:19:13 +0000</created>
                <updated>Wed, 13 Jan 2010 13:45:50 +0000</updated>
                            <resolved>Wed, 6 Jan 2010 19:39:40 +0000</resolved>
                                    <version>1.2</version>
                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="11661" author="desmax" created="Thu, 7 Jan 2010 10:45:01 +0000"  >&lt;p&gt;I don&apos;t have sharp eye like you &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;br/&gt;
Thanks a lot.&lt;br/&gt;
Sorry for the noise.&lt;/p&gt;</comment>
                            <comment id="11657" author="kristina" created="Thu, 7 Jan 2010 09:57:05 +0000"  >&lt;p&gt;Here are your ids (spaces added for emphasis):&lt;/p&gt;

&lt;p&gt;4b4599fe45d2ba538   9   58a21c&lt;br/&gt;
4b4599fe45d2ba538   a   58a21c&lt;br/&gt;
4b4599fe45d2ba538   b   58a21c&lt;/p&gt;</comment>
                            <comment id="11656" author="desmax" created="Thu, 7 Jan 2010 09:36:50 +0000"  >&lt;p&gt;No, the second example is more explicit but the logic it&apos;s the same:&lt;/p&gt;

&lt;p&gt;mapOne   =&amp;gt; userOne.toMap()&lt;br/&gt;
mapTwo   =&amp;gt; userTwo.toMap()&lt;br/&gt;
mapThree =&amp;gt; userThree.toMap()&lt;/p&gt;

&lt;p&gt;repo.getCollection().insert(users)  =&amp;gt; datastore.getDB().getCollection(&quot;usersTest&quot;).insert(users) &lt;/p&gt;

&lt;p&gt;I have the same problem if replace the list insert with three DBObject insert:&lt;/p&gt;

&lt;p&gt;datastore.getDB().getCollection(&quot;usersTest&quot;).insert(new BasicDBObject(one));&lt;br/&gt;
datastore.getDB().getCollection(&quot;usersTest&quot;).insert(new BasicDBObject(two));&lt;br/&gt;
datastore.getDB().getCollection(&quot;usersTest&quot;).insert(new BasicDBObject(three));&lt;/p&gt;

&lt;p&gt;How can obtain dirfferent ids ?&lt;br/&gt;
What&apos;s wrong ?&lt;br/&gt;
Thanks&lt;/p&gt;
</comment>
                            <comment id="11655" author="eliot" created="Thu, 7 Jan 2010 07:34:11 +0000"  >&lt;p&gt;Those are differnt&lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;. &lt;/p&gt;</comment>
                            <comment id="11654" author="desmax" created="Thu, 7 Jan 2010 03:26:51 +0000"  >&lt;p&gt;Eliot, this is example code:&lt;/p&gt;

&lt;p&gt;@Test&lt;br/&gt;
public void getInsertCollection() {&lt;br/&gt;
     Map mapOne = new HashMap();&lt;br/&gt;
       mapOne.put(&quot;ZipCode&quot;,&quot;05125&quot;);&lt;br/&gt;
       mapOne.put(&quot;City&quot;,&quot;Modena&quot;);&lt;br/&gt;
       mapOne.put(&quot;Country&quot;,&quot;Italy&quot;);&lt;br/&gt;
       mapOne.put(&quot;Province&quot;,&quot;MO&quot;);&lt;br/&gt;
       mapOne.put(&quot;Region&quot;,&quot;Emilia Romagna&quot;);&lt;br/&gt;
       mapOne.put(&quot;Street&quot;,&quot;V.le Sidney Sonnino 133&quot;);&lt;br/&gt;
       mapOne.put(&quot;DateOfBirth&quot;,new Date());&lt;br/&gt;
       mapOne.put(&quot;Email&quot;,&quot;jack.folla@yahoo.it&quot;);&lt;br/&gt;
       mapOne.put(&quot;Name&quot;,&quot;Jack&quot;);&lt;br/&gt;
       mapOne.put(&quot;Surname&quot;,&quot;Folla&quot;);&lt;br/&gt;
       mapOne.put(&quot;SensibleData&quot;,&quot;no sensible data&quot;);&lt;br/&gt;
       mapOne.put(&quot;AcceptSms&quot;,true);&lt;br/&gt;
       mapOne.put(&quot;Mobile&quot;,&quot;33912345563&quot;);&lt;br/&gt;
       mapOne.put(&quot;TelephoneWork&quot;,&quot;0709876543&quot;);&lt;br/&gt;
       mapOne.put(&quot;CenterId&quot;,&quot;centerThree&quot;);&lt;br/&gt;
       mapOne.put(&quot;Description&quot;,&quot;descrThree&quot;);&lt;br/&gt;
       mapOne.put(&quot;GroupId&quot;,&quot;groupThree&quot;);&lt;br/&gt;
       BasicDBObject one = new BasicDBObject(mapOne);&lt;/p&gt;

&lt;p&gt;       Map mapTwo = new HashMap();&lt;br/&gt;
       mapTwo.put(&quot;ZipCode&quot;,&quot;09129&quot;);&lt;br/&gt;
       mapTwo.put(&quot;City&quot;,&quot;Cagliari&quot;);&lt;br/&gt;
       mapTwo.put(&quot;Country&quot;,&quot;Italy&quot;);&lt;br/&gt;
       mapTwo.put(&quot;Province&quot;,&quot;OR&quot;);&lt;br/&gt;
       mapTwo.put(&quot;Region&quot;,&quot;Sardegna&quot;);&lt;br/&gt;
       mapTwo.put(&quot;Street&quot;,&quot;V.le Sidney Sonnino 4&quot;);&lt;br/&gt;
       mapTwo.put(&quot;DateOfBirth&quot;,new Date());&lt;br/&gt;
       mapTwo.put(&quot;Email&quot;,&quot;jack.folla@gmail.com&quot;);&lt;br/&gt;
       mapTwo.put(&quot;Name&quot;,&quot;Jim&quot;);&lt;br/&gt;
       mapTwo.put(&quot;Surname&quot;,&quot;Finn&quot;);&lt;br/&gt;
       mapTwo.put(&quot;SensibleData&quot;,&quot;no sensible data&quot;);&lt;br/&gt;
       mapTwo.put(&quot;AcceptSms&quot;,true);&lt;br/&gt;
       mapTwo.put(&quot;Mobile&quot;,&quot;3391234556&quot;);&lt;br/&gt;
       mapTwo.put(&quot;TelephoneWork&quot;,&quot;070987654&quot;);&lt;br/&gt;
       mapTwo.put(&quot;CenterId&quot;,&quot;centerFour&quot;);&lt;br/&gt;
       mapTwo.put(&quot;Description&quot;,&quot;descr&quot;);&lt;br/&gt;
       mapTwo.put(&quot;GroupId&quot;,&quot;groupFour&quot;);&lt;br/&gt;
       BasicDBObject two = new BasicDBObject(mapTwo);&lt;/p&gt;

&lt;p&gt;       Map mapThree = new HashMap();&lt;br/&gt;
       mapThree.put(&quot;ZipCode&quot;,&quot;09100&quot;);&lt;br/&gt;
       mapThree.put(&quot;City&quot;,&quot;Cagliari&quot;);&lt;br/&gt;
       mapThree.put(&quot;Country&quot;,&quot;Campidano&quot;);&lt;br/&gt;
       mapThree.put(&quot;Province&quot;,&quot;CA&quot;);&lt;br/&gt;
       mapThree.put(&quot;Region&quot;,&quot;Sardegna&quot;);&lt;br/&gt;
       mapThree.put(&quot;Street&quot;,&quot;V.le Europe 4&quot;);&lt;br/&gt;
       mapThree.put(&quot;DateOfBirth&quot;,new Date());&lt;br/&gt;
       mapThree.put(&quot;Email&quot;,&quot;max@gmail.com&quot;);&lt;br/&gt;
       mapThree.put(&quot;Name&quot;,&quot;Paperino&quot;);&lt;br/&gt;
       mapThree.put(&quot;Surname&quot;,&quot;Paolino&quot;);&lt;br/&gt;
       mapThree.put(&quot;SensibleData&quot;,&quot;no sensible data&quot;);&lt;br/&gt;
       mapThree.put(&quot;AcceptSms&quot;,true);&lt;br/&gt;
       mapThree.put(&quot;Mobile&quot;,&quot;3391234557&quot;);&lt;br/&gt;
       mapThree.put(&quot;TelephoneWork&quot;,&quot;070987654&quot;);&lt;br/&gt;
       mapThree.put(&quot;CenterId&quot;,&quot;centerFive&quot;);&lt;br/&gt;
       mapThree.put(&quot;Description&quot;,&quot;descr&quot;);&lt;br/&gt;
       mapThree.put(&quot;GroupId&quot;,&quot;groupFive&quot;);&lt;br/&gt;
       BasicDBObject three = new BasicDBObject(mapThree);&lt;/p&gt;

&lt;p&gt;       List&amp;lt;DBObject&amp;gt; users = new ArrayList&amp;lt;DBObject&amp;gt;();&lt;br/&gt;
       users.add(new BasicDBObject(one));&lt;br/&gt;
       users.add(new BasicDBObject(two));&lt;br/&gt;
       users.add(new BasicDBObject(three));&lt;/p&gt;

&lt;p&gt;       datastore.getDB().getCollection(&quot;usersTest&quot;).insert(users);&lt;/p&gt;

&lt;p&gt;       DBCursor cursor = getDB().getCollection(&quot;usersTest&quot;).find();&lt;br/&gt;
       while(cursor.hasNext())&lt;/p&gt;
{
           DBObject current = cursor.next();
           StringBuilder sb = new StringBuilder();
           sb.append(&quot;id:&quot;).append(current.get(&quot;_id&quot;)).append(&quot; name:&quot;).append(current.get(&quot;Name&quot;)).append(&quot; Surname:&quot;).append(current.get(&quot;Surname&quot;));
           System.out.println(sb.toString());
       }

&lt;p&gt;       getDB().getCollection(&quot;usersTest&quot;).drop();&lt;br/&gt;
 }&lt;/p&gt;


&lt;p&gt;and produce the output:&lt;/p&gt;

&lt;p&gt;id:4b4599fe45d2ba538958a21c name:Jack Surname:Folla&lt;br/&gt;
id:4b4599fe45d2ba538a58a21c name:Jim Surname:Finn&lt;br/&gt;
id:4b4599fe45d2ba538b58a21c name:Paperino Surname:Paolino&lt;/p&gt;</comment>
                            <comment id="11650" author="eliot" created="Wed, 6 Jan 2010 19:39:40 +0000"  >&lt;p&gt;i tried to find any issue with the code and tried your snippet but can&apos;t find anything wrong.&lt;br/&gt;
Certainly can&apos;t reproduce.&lt;br/&gt;
The current algorithm is very fast, and is guaranteed not to generate dups.&lt;/p&gt;

&lt;p&gt;If you can send a full program that displays the error, can take a look.&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|hrhdd3:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14965</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>