Assuming you are using mongoose and express, in your controller you can do:
function findOneInput(req, res) {
Model.findOne({ field: req.query.input }, function (error, input) {
// Trata erro
if(error) {
console.error(error)
res.status(500).msg({ msg: 'Um erro ocorreu' })
}
// Manda o documento para o usuario
res.json(input)
})
}
In the view, you would need to make a request to your API, passing the input to the query. The URI would be: example.com/api/nome-da-rota?input=valor-do-usuario
. The API would return you null
if the document does not exist in the DB and would return the document if it exists. Then just do an if.
Q.: That's pretty general, that's a guess according to what you posted. It may be that other adjustments have to be made in relation to security, performance and even the way you have adjusted your data.