Skip to content

Instantly share code, notes, and snippets.

@epjuan21
Created February 14, 2023 00:16
Show Gist options
  • Save epjuan21/69d6aa23cb1c3e46b3fadf3fbf5a6b9b to your computer and use it in GitHub Desktop.
Save epjuan21/69d6aa23cb1c3e46b3fadf3fbf5a6b9b to your computer and use it in GitHub Desktop.
Función para buscar un termino determinado en dos campos de una colección en mondodb
exports = async function(payload, response){
const { q } = payload.query;
const mongodb = context.services.get("mongodb-atlas");
const serviciosCollection = mongodb.db("referencias").collection("Servicios");
var findResult;
try {
findResult = await serviciosCollection.find({
$or: [
{ Nombre: {$regex: `${q}`, $options: 'i'} },
{ Descripcion: {$regex: `${q}`, $options: 'i'} }
]
})
} catch(err) {
console.log("Error occurred while executing findOne:", err.message);
return { error: err.message };
}
return { result: findResult };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment