I am trying to get documents in the database that match the string but it does not work when i pass in the variable.
I have a string serviceString and serviceString = "test1", "test2", "test3"
query = db.collection('Services').find({
'Service': {
$in: [serviceString]
}
});
This returns nothing from the DB BUT if I do this:
query = db.collection('Services').find({
'Service': {
$in: ["test1", "test2", "test3"]
}
});
It works and returns what I need.
Do you know why its not working, I am thinking the string is putting commas in as a string. Whats a way I can do this because the string is a input from a user so it can change so I cant hard code the variables in the query?
query = db.collection('Services').find({ 'Service': { $in: serviceString.split(',') } });