2015-03-13 571 views

回答

5

toHexString方法以24字節的十六進制字符串表示形式返回ObjectID標識符。

// Create a new ObjectID 
var objectId = new ObjectID(); 
// Verify that the hex string is 24 characters long 
assert.equal(24, objectId.toHexString().length); 

您將不再需要Base64編碼調用一個ObjectIdtoString因爲它已經返回一個十六進制數的結果。您也可以撥打:_id.toHexString()直接獲取十六進制值。
點擊此鏈接查看MongoDB源代碼(toString just wraps toHexString)。

相關問題