1
我在使用Node.js v0.12.0和MongoDB驅動程序v1.4.34。那麼,在使用toString和toHexString方法將ObjectID轉換爲String之間有什麼區別嗎?MongoDB本地︰toString和toHexString方法之間有任何區別?
我在使用Node.js v0.12.0和MongoDB驅動程序v1.4.34。那麼,在使用toString和toHexString方法將ObjectID轉換爲String之間有什麼區別嗎?MongoDB本地︰toString和toHexString方法之間有任何區別?
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編碼調用一個ObjectId
toString
因爲它已經返回一個十六進制數的結果。您也可以撥打:_id.toHexString()
直接獲取十六進制值。
點擊此鏈接查看MongoDB源代碼(toString just wraps toHexString)。