There are some severe errors in your code.
First of all:
db.ds.find({querystring}).count() # SyntaxError here
The problem that this line gives SyntaxError because {object} syntax is a literal for set built-in type, which is available since Python 2.7.x version, so, here you're trying to create a set consisting of one string:
{object} # creates set since Python 2.7
{object1: object2} # creates dict (object1 should be [hashable][1])
Let's see an example of creating set in Python 2.7:
s = {1, 2, 3} # Creating set of three unique elements ({} - set literal)
d = {1: 'a', 2: 'b'} # Creating dict of number->letters ({:} - dict literal)
The second thing is that MongoDB Python driver (I assume that you use Pymongo) doesn't accept strings as queries. It has it's own API and all queries are made via dicts representing JSON objects (note, that Mongo stores all objects inside in binary representation of JSON called BSON).
So here, remember first problem, when you're trying to create set instead of dict).
Conclusion:
- Use
dicts to create appropriate Pymongo queries.
- Create dicts properly (not sets).