When you use pymongo, everything becomes a unicode object. Unicode and str objects have the same API for our purposes, so this code will work with either. Also, in Python < 3.0, it's important for code to use unicode internally. In Python >= 3.0, all strings are natively unicode objects.