MongoDB Node check if objectid is valid

前端 未结 8 2378
甜味超标
甜味超标 2020-11-28 11:26

How can I check whether an ObjectID is valid using Node\'s driver

I tried :

var BSON = mongo.BSONPure;
console.log(\"Validity: \"  + BSON.ObjectID.is         


        
8条回答
  •  粉色の甜心
    2020-11-28 12:05

    Follow this regular expression :

    in js

    new RegExp("^[0-9a-fA-F]{23}$").test("5e79d319ab5bfb2a9ea4239")

    in java

    Pattern.compile("^[0-9a-fA-F]{23}$").matcher(sanitizeText(value)).matches()

提交回复
热议问题