0

I have the following python script:

import pdb
import sys
import os
import csv
import pymongo
from pymongo import MongoClient

def main():
    pass

def getWholeCollection(collection_name):
    for property in collection_name.find("{"zip":33801}"):
        print property


if __name__ == '__main__':
    client = MongoClient()
    data_base = client.hkpr_dbw
    properties_collection = data_base.properties

    getWholeCollection(properties_collection)

I keep getting an error around {"zip":33801} which works fine in the mongo shell. I tried """{"zip":33801}""".

I'd like to make the query a variable at some point. How do I use these strings?

3
  • 2
    Try for property in collection_name.find({"zip":33801}): Commented Apr 15, 2015 at 20:20
  • that's it. no need for quotes. Thanks! want to put that as the answer? Commented Apr 15, 2015 at 20:32
  • 2
    No worries :-) I think @DanielRoseman answer below suffices. Commented Apr 15, 2015 at 20:37

1 Answer 1

4

You don't need to put it in a string. The MongoDB driver will convert the Python dict into the relevant format.

collection_name.find({"zip": 33801})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.