Skip to content

Instantly share code, notes, and snippets.

@adamshamsudeen
Created November 30, 2018 08:00
Show Gist options
  • Save adamshamsudeen/b54f371e3f43d1c5ff5c73c63ba97649 to your computer and use it in GitHub Desktop.
Save adamshamsudeen/b54f371e3f43d1c5ff5c73c63ba97649 to your computer and use it in GitHub Desktop.
Basics of using mongodb with python
from pymongo import MongoClient
client = MongoClient()
db = client.alexa
users_collection = db.user_details
#insert
users_collection.insert_one({"user":id,
"time":datetime.datetime.utcnow(),
"activated":False,
"token": token})
#search
user_info = users_collection.find_one({"user":id})
#update
status = users_collection.update_one({"token":id}, {"$set":{"activated":True, "time":datetime.datetime.utcnow()}}, upsert=True)
"""
$ brew services start mongodb
$ mongo
> show dbs
> use alexa
> db.user_details.find();
> db.user_details.drop();
$ brew services stop mongodb
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment