Created
February 14, 2023 00:16
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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