From what it sounds like, you will have to know that the inputValue can be more characters (since we are talking strings) than your documents' IDs.
If you know that your input could be the ID you want followed by 'n' number of zero's (based on your example) then your regex would look more like:
inputValue = inputValue.replace("0", "");
db.getCollection('STUDENT').find( { Studentid:{$regex : inputValue + '[0]*'}});
My real suggestion is to use a number for the ID (be it int
or long
, that way you can do db.getCollection('STUDENT').find(eq("Sudentid", <inputValue>));
or if you're looking for multiple students
db.getCollection('STUDENT').find(gte("Sudentid", <inputValue>));
which returns all documents with Studentid
greater than or equal to the inputValue.
Disclaimer: I'm not sure which version of the Mongo-driver you're using, but here are the docs I used and what my answer is based on: Mongo Driver Docs