Reputation: 109
Trying to search through my mongoDB database using variable names not by specifying the exact search. Is it possible to do this? No matter how i try to format the variable I can't get a successful search. I'm trying to do something like the bottom line below
let url3 = 'http://cs544.io/11jgry2';
const ret = await dbTable.find({"shortUrl" : "http://cs544.io/11jgry2"}); //Works
const ret = await dbTable.find({"shortUrl" : url3}); //Doesn't work
Upvotes: 0
Views: 895
Reputation: 331
Use $eq it Specifies equality condition. The $eq operator matches documents where the value of a field equals the specified value.
Check this this for further explanation and examples
Upvotes: 1