mongoose objectid to number
This is untested, but I think you'd want to do something like this:
var idNum = parseInt(objectId.valueOf(), 16);
MongoDB ObjectIDs are essentially 12 byte hex strings. This makes them larger than the MAX_VALUE
for a JavaScript Number (2^53), so you may run into errors with the conversion. But, it looks like Number.MAX_VALUE
in my node.js environment (0.11.6) can handle that value. So you might be safe...
Why are you converting an Object ID to a Number though? You really shouldn't be performing arithmetic operations on an ObjectId...
try using the virtual id onstead of _id
option(data-id=val.id) #{val.name}
instead of
option(data-id=val._id) #{val.name}