I’m trying to search mongo collection to retrieve some value based on variable name, like this
sportName = “/Basketball/i”;
db.Team.find({name:sportName}).forEach(function (team) {
print(team.name);
});
It always returns nothing although when I search using the following script it returns result
db.Team.find({name: /Basketball/i}).forEach(function (team) {
print(team.name);
});
Thanks
You can’t assign a regex to a variable like this:
Do it like this: