-
Type: Bug
-
Resolution: Won't Fix
-
Priority: Major - P3
-
Affects Version/s: None
-
None
-
Environment:OS:
node.js / npm versions:
Additional info:
-
2
-
Not Needed
Using mongosh 1.6.0 the following code will fail:
(new ObjectId()).getTimestamp() // TypeError: Cannot read properties of undefined (reading 'slice')
The above does work with the legacy shell and appears to be due to the implementation of ObjectId.prototype.getTimestamp calling ObjectId.prototype.valueOf, which returns undefined (instead of a string).
This can be fixed by changing ObjectId.prototype.getTimestamp to:
ObjectId.prototype.getTimestamp = function() { if (this.toHexString) return new Date(parseInt(this.toHexString().slice(0, 8), 16) * 1000); return new Date(parseInt(this.toString('hex').slice(0, 8), 16) * 1000); };
- duplicates
-
MONGOSH-1502 valueOf() method does not work on ObjectId
- Closed