An _id validation technique

16 views
Skip to first unread message

Ray V

unread,
Oct 16, 2014, 8:51:22 AM10/16/14
to cfmo...@googlegroups.com
I'd like to share a chunk of knowledge I picked up. 

I had a need to validate a string as a mongodb _id. Prior to putting on the regex hat, I stumbled on to this post: http://stackoverflow.com/questions/13850819/can-i-determine-if-a-string-is-a-mongodb-objectid

The following function is how I implemented the technique in a (cfmongodb) app I'm maintaining. 

<cffunction name="isValid_id" returntype="boolean" access="public" description="I determine if the string argument is a valid mongodb _id">
<cfargument name="_id" type="string" required="true" />
<cfscript>
                       // mongoUtils should already be in the application scope
                       return application.mongoUtils.getMongoFactory().getObject("org.bson.types.ObjectId").isValid(arguments._id);
</cfscript>
</cffunction> 


Enjoy!

Marc Esher

unread,
Oct 21, 2014, 7:23:36 AM10/21/14
to cfmo...@googlegroups.com
Thanks, Ray!

--
You received this message because you are subscribed to the Google Groups "CFMongoDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cfmongodb+...@googlegroups.com.
To post to this group, send email to cfmo...@googlegroups.com.
Visit this group at http://groups.google.com/group/cfmongodb.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages