Skip to content

Instantly share code, notes, and snippets.

@shinriyo
Created December 8, 2013 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shinriyo/7856219 to your computer and use it in GitHub Desktop.
Save shinriyo/7856219 to your computer and use it in GitHub Desktop.
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