<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Thu Feb 08 08:57:19 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-2477] Invalid ObjectId generated by MongoDB</title>
                <link>https://jira.mongodb.org/browse/JAVA-2477</link>
                <project id="10006" key="JAVA">Java Driver</project>
                    <description>&lt;p&gt;Add some records to collection with java driver, it will generate object id for each records automatically. In my database, it generate below Object Id by MongoDB:&lt;br/&gt;
ObjectId(&quot;58b38f407decdd8070b2df96&quot;)&lt;/p&gt;

&lt;p&gt;It&apos;s invalid object id, my test:&lt;/p&gt;

&lt;p&gt;import org.bson.types.ObjectId;&lt;br/&gt;
public class Test {&lt;br/&gt;
	public static void main(String[] args) &lt;/p&gt;
{
		// TODO Auto-generated method stub
		String idStr = &quot;58b38f407decdd8070b2df96&quot;;
		ObjectId id = new ObjectId(idStr);
		System.out.println(id.getProcessIdentifier());
	}
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;Print result: &lt;br/&gt;
-32656&lt;/p&gt;

&lt;p&gt;The processIdentifier is a negative number. Now I map the object id to JSP file, then use JS to generate object id, the new object will contains endash, and it&apos;s an invalid object id.&lt;/p&gt;

&lt;p&gt;It happened sometimes but not frequently. The attachment is another invalid object id, notice the processIdentifier value.&lt;/p&gt;

&lt;p&gt;I&apos;m not sure it&apos;s a java driver bug or core server bug.&lt;/p&gt;</description>
                <environment>Cent OS 7</environment>
        <key id="367493">JAVA-2477</key>
            <summary>Invalid ObjectId generated by MongoDB</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="13202">Works as Designed</resolution>
                                        <assignee username="ross@mongodb.com">Ross Lawley</assignee>
                                    <reporter username="Kimi">KimiLiu [X]</reporter>
                        <labels>
                    </labels>
                <created>Fri, 24 Mar 2017 06:59:24 +0000</created>
                <updated>Fri, 27 Oct 2023 13:21:14 +0000</updated>
                            <resolved>Thu, 22 Jun 2017 16:42:39 +0000</resolved>
                                    <version>3.4.1</version>
                                                    <component>BSON</component>
                                        <votes>0</votes>
                                    <watches>3</watches>
                                                                                                                <comments>
                            <comment id="1604390" author="jeff.yemin" created="Thu, 22 Jun 2017 16:42:27 +0000"  >&lt;p&gt;There are several situations where the JVM will be unable to determine the process identifier.  The driver makes a best effort to get one and then has several fallbacks (see org.bson.types.ObjectId#createProcessIdentifier for details), which as Ross said can result in a negative number in some situations.  &lt;/p&gt;

&lt;p&gt;My advice is not to rely on the process identifier being a positive number.  I suggest than you map an ObjectId to its hex string value in your JSP, rather than as a map of the constituent parts.&lt;/p&gt;</comment>
                            <comment id="1532979" author="kimi" created="Mon, 27 Mar 2017 03:58:53 +0000"  >&lt;p&gt;Hi, Lawley,&lt;/p&gt;

&lt;p&gt;Your answer makes me a litter confuse.&lt;br/&gt;
Firstly, you can add the objectid i given in monodb command, that right.&lt;br/&gt;
Secondly, How can I get a negative process id? Because my project is Java project, so I make a test in eclipse withe below steps:&lt;br/&gt;
1. open new Java project, and create a &quot;test&quot; class&lt;br/&gt;
2. import bson-3.2.1 jar file to project.&lt;br/&gt;
3. coding in test class as below:&lt;/p&gt;

&lt;p&gt;import org.bson.types.ObjectId;&lt;/p&gt;

&lt;p&gt;public class Test {&lt;/p&gt;

&lt;p&gt;	public static void main(String[] args) &lt;/p&gt;
{
		// TODO Auto-generated method stub
		String idStr = &quot;58b38f407decdd8070b2df96&quot;;
		ObjectId id = new ObjectId(idStr);
		System.out.println(&quot;process id is: &quot; + id.getProcessIdentifier());
		System.out.println(&quot;machine id is: &quot; + id.getMachineIdentifier());	
		System.out.println(&quot;timestamp id is: &quot; + id.getTimestamp());
	}
&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;4. Check eclipse console, no Java error with below print result:&lt;br/&gt;
process id is: -32656&lt;br/&gt;
machine id is: 8252637&lt;br/&gt;
timestamp id is: 1488162624&lt;/p&gt;

&lt;p&gt;Now I can get the process id is &quot;-32656&quot;. In fact, my focus is whether a negative process identifier is right in objectid structure. I have ask this question in stack overflow but no response.&lt;/p&gt;

&lt;p&gt;As you said above: This can happen when the Java driver fails to get process identifier from JMX. But no java error report in my project, and most of objectid is right for me.&lt;/p&gt;</comment>
                            <comment id="1531948" author="ross@10gen.com" created="Fri, 24 Mar 2017 10:05:17 +0000"  >&lt;p&gt;Hi &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=Kimi&quot; class=&quot;user-hover&quot; rel=&quot;Kimi&quot;&gt;Kimi&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thanks for the ticket, &lt;tt&gt;ObjectId(&quot;58b38f407decdd8070b2df96&quot;)&lt;/tt&gt; is valid and perfectly usable as an ObjectId. The components of an ObjectId can be found in the &lt;a href=&quot;https://docs.mongodb.com/manual/reference/method/ObjectId/&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;documentation&lt;/a&gt;: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The 12-byte ObjectId value consists of:&lt;/p&gt;

&lt;ul&gt;
	&lt;li&gt;a 4-byte value representing the seconds since the Unix epoch,&lt;/li&gt;
	&lt;li&gt;a 3-byte machine identifier,&lt;/li&gt;
	&lt;li&gt;a 2-byte process id, and&lt;/li&gt;
	&lt;li&gt;a 3-byte counter, starting with a random value.&lt;/li&gt;
&lt;/ul&gt;

&lt;/blockquote&gt;

&lt;p&gt;Which is why the ObjectId will happily roundtrip to and from the server:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;MongoDB Enterprise &amp;gt; db.test.insert({_id: ObjectId(&quot;58b38f407decdd8070b2df96&quot;) })&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;WriteResult({ &quot;nInserted&quot; : 1 })&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;MongoDB Enterprise &amp;gt; db.test.findOne()&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{ &quot;_id&quot; : ObjectId(&quot;58b38f407decdd8070b2df96&quot;) }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;MongoDB Enterprise &amp;gt;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;How can I get a negative process id? This can happen when the Java driver fails to get process identifier from JMX.  If this happens it falls back to using a random number instead and will log a warning message informing the user.&lt;/p&gt;

&lt;p&gt;I hope that answers your questions.  For future reference, the best place for questions regarding MongoDB usage or the Java driver specifics is the &lt;a href=&quot;https://groups.google.com/forum/#!forum/mongodb-user&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;mongodb-user mailinglist&lt;/a&gt; or &lt;a href=&quot;http://stackoverflow.com&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;stackoverflow&lt;/a&gt; as you will reach a boarder audience there.  If your business requires an answer from MongoDB within a time frame then we do offer &lt;a href=&quot;https://www.mongodb.com/products/production-support&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;production support&lt;/a&gt;.&lt;/p&gt;

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

&lt;p&gt;Ross&lt;/p&gt;</comment>
                            <comment id="1531918" author="kimi" created="Fri, 24 Mar 2017 07:09:21 +0000"  >&lt;p&gt;bson jar version: 3.2.1&lt;br/&gt;
JDK: 1.8.111&lt;br/&gt;
mongo db version: 3.4.1&lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                            <attachment id="152331" name="Untitled.png" size="525947" author="Kimi" created="Fri, 24 Mar 2017 06:56:28 +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|hsx4pb:</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>