MongoDB - Find records in one collection that match string in 2nd collection
You're turning the result of db.codes.find() into a list, but you're just iterating over it anyway. Why not just leave it in whatever form it arrives? If it can be converted to a list it can probably be iterated over. This would save you the time of conversion and mean you might not need to have a full list stored in memory.

Also x isn't a great name for the temporary value when you could just use code and take up only 3 more letters.