When debugging the callback, mongooseI found that either underscore.js or the JavaScript language itself seems to have problems with large numbers.
In the example below, I save a small number and a string containing the ObjectId of mongoose (24-digit number) to show the problem as clearly as possible.
var users = ["32", "300000000000000000000002"];
alert(_.contains(users, "32")); // true
alert(_.contains(users, (32).toString())); // true
alert(_.contains(users, "300000000000000000000002")); // true
alert(_.contains(users, (300000000000000000000002).toString())); // false - wait wat ?
My question, of course, is how to make the last call true?
I would prefer not to convert the array usersto an array of numbers, because (1) the array can be huge in a production context and (2) I may need to perform other operations on the array.
source
share