How can I check whether an ObjectID is valid using Node’s driver
I tried :
var BSON = mongo.BSONPure;
console.log("Validity: " + BSON.ObjectID.isValid('ddsd'))
But I keep getting an exception instead of a true or false. (The exception is just a ‘throw e; // process.nextTick error, or ‘error’ event on first tick’
This is a simple check – is not 100% foolproof
You can use this Regular Expression if you want to check for a string of 24 hex characters.
Regex taken from github.com/mongodb/js-bson/…/objectid.ts
For a better check use:
isValidcode github.com/mongodb/js-bson/…/objectid.ts