Negative process id in object id

Add some records to collection using java driver, it will automatically generate object id for each record. In my database, it generates below MongoDB object id:

ObjectId("58b38cd57decdd8070b2df8f")

      

Then I do a test for the current object id:

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

      

java no error with below print result: -32656

Process ID is a negative number in the object ID structure. I'm not sure if this is a java driver bug or a main server bug.

In my project I need to send an object id to a JSP file and generate an object id from the hosted object structure. Due to the wrong process ID, the object ID generated by the JS function will contain en dash. This is an invalid object identifier.

the object structure sent to the JSP file:

counter:11722639
date:1488162005000
machineIdentifier:8252637
processIdentifier:-32656
time:1488162005000
timeSecond:1488162005
timestamp:1488162005

      

New object id generated by the object structure:

58b38cd57decdd-7f90b2df8f

      

JS function generates object id from object structure:

function parseObjectId(objectId){
var timestamp = objectId.timestamp;
var machineIdentifier = objectId.machineIdentifier;
var processIdentifier = objectId.processIdentifier;
var counter = objectId.counter;
return toFixedLengthHex(timestamp,8) + toFixedLengthHex(machineIdentifier,6) + toFixedLengthHex(processIdentifier,4) + toFixedLengthHex(counter,6);

      

}

mongodb version: 3.4.1 BSON version: 3.2.1 Mongo-java-driver: 3.2.2

+3


source to share





All Articles