Hello all,
I have a project where the database needs to be queried for at least one of a variable list of languages. I am accessing the MongoDB from node.js.
const cursor = client.db(<mydatabase>).collection(<collection>).find({
"discipline": reqdiscipline,
"available": availability,
$or: [ { "language": reqlanguage[0] }, { "language" : reqlanguage[1]} ]
} ) ;
“discipline” has only one possible value from a list of choices
“available” is a boolean
“language” can have 1,2,3… possible values
Here I have it set up to take $or parameters from an array “language” with two elements which works fine. My problem is that there may be more or less elements in the array. Never zero elements. How can I dynamically create the $or query when the array “reqlanguage” has a diffent size each time I make the query. I tried it as a string with various parts escaped but didn’t have any success.
Thanks for any help, this should be the last hurdle in my project.
John