Created
December 8, 2013 11:31
-
-
Save shinriyo/7856219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from datetime import datetime | |
from pymongo import Connection | |
from pymongo.errors import ConnectionFailure | |
def main(): | |
try: | |
c = Connection(host="localhost", port=27017) | |
except(ConnectionFailure, e): | |
sys.stderr.write("Could not connect to MongoDB: %s" % e) | |
sys.exit(1) | |
dbh = c["mydb"] | |
assert dbh.connection == c | |
#users = dbh.users.find({"name":"shinriyo"}) | |
users = dbh.users.find() | |
for user in users: | |
print (user.get("name")) | |
print (user.get("score")) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment