I am trying to query a collection and want to do it on just the beginning of the postal code. I've tried following the instructions but get 0 documents:
> db.listings.count({"house.postalcode" : "EH21 8RG"})
2
> db.listings.count({"house.postalcode" : {"$regex" : "/^EH21/"}})
0
I know I must be missing something but I've checked the regex online and you can see the results above of the two queries.. help!
$regexremove either remove string quotes (to make it a regex expression) and use :{"$regex" : /^EH21/}or use the string quotes without the forward slashes:{"$regex" : "^EH21"}docs