replace $ with # in boolean expressions because $ generates invalid BSON.