Skip to content

Instantly share code, notes, and snippets.

@shinriyo
Created December 8, 2013 11:30
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/7856207 to your computer and use it in GitHub Desktop.
Save shinriyo/7856207 to your computer and use it in GitHub Desktop.
import sys
import hashlib
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)
secret_key = 'mySecretKey'
name = 'shinriyo'
score = '10'
dbh = c["mydb"]
real_hash = hashlib.md5(bytes(name + score + secret_key, "utf-8")).digest()
assert dbh.connection == c
user_doc = {
"name" : name,
"score" : score
}
dbh.users.insert(user_doc, safe=True)
print("Successfully inserted document: %s" % user_doc)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment