pymongo - Using JSON in Python to send query to MongoDB -
i'm trying create following query in python connection have mongodb.
db.deal.find({"id":"11223|14589"})
by using writing following code:
import json unique_id = "11223|14589" query = json.dumps({"id":"%s"}) %(unique_id)
unfortunately, creates string, , results don't returned results mongodb. querying manually using string created in variable query returns results. know might working pymongo?
not sure you're trying achieve here.
first of all, should not have serialize json. not replace parts of string after it's serialized.
second, unique_id
1 value you're looking for? if so, pass query:
unique_id = '11223|14589' foo.find({'id': unique_id})
or these 2 values you'd search for?
unique_id = '11223|14589' ids = unique_id.split('|') # ['11223', '14589'] foo.find({'id': {'$in': ids}})
Comments
Post a Comment