Joi: Adding ObjectID validator ?

Created on 26 Feb 2015  路  11Comments  路  Source: sideway/joi

Hi !
Before I try to code anything, what do you think about adding a validator for Mongodb's ObjectIDs ?
As Mongodb is widely used, it may be a good thing. But it may also be seen as a useless overhead.

Please take in account the fact that if #521 gets merged, this would become useless.

support

Most helpful comment

We can use mongoose.Types.ObjectId.isValid for validating ObjectId is valid or not.

if (!mongoose.Types.ObjectId.isValid(req.body.id)) {
    return res.status(400).send("Invalid object id");
}

All 11 comments

God. Thanks.
At the time, I was just checking in the _handler_ block, but it's gonna be cleaner now.

:tada:

(Gonna follow you, to say thanks once again)

Thanks! :smile:

The PR you mentioned won't be merged.

Sad.

Not if it's done in another way.

@Marsup is that a teaser for things to come?

We can use mongoose.Types.ObjectId.isValid for validating ObjectId is valid or not.

if (!mongoose.Types.ObjectId.isValid(req.body.id)) {
    return res.status(400).send("Invalid object id");
}

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

normancarcamo picture normancarcamo  路  3Comments

sergibondarenko picture sergibondarenko  路  3Comments

PaunPrashant picture PaunPrashant  路  3Comments

mohamadresaaa picture mohamadresaaa  路  3Comments

kevbook picture kevbook  路  4Comments