Does someone know how to dynamically adjust a query to MongoDB api ?
For exemple, if I have a data that is defined with 3 fields :
Car {Driver, ProductionYear, Brand}
Still for example, I would like to make a function that takes 2 couple of parameters (2 of the 3 fields of my data Car associated with the value wanted) and return a dynamic query that allows to search by these parameters.
function getQuery(field, value, current_query) {
// I don't know here how to make the custom request excepting using a if forest which I do not think is a proper way to do this. I would like the function to add another element to the query and then return the query updated
return (query);
}
//then I could use :
current_query = getQuery("Brand", "Ford", current_query) {
current_query = getQuery("ProductionYear", "2000", current_query) {
//current_query should be equal to { Brand: { $eq: "Ford" }, ProductionYear: { $eq: "2000" } }
db.collection("Cars").find(query).toArray()
Does anyone have an idea ?
Thanks