Skip to content

Instantly share code, notes, and snippets.

@nazarsa
Created November 15, 2016 15:47
Show Gist options
  • Save nazarsa/7204d0e4ab41961ec3ffa1b184d996a9 to your computer and use it in GitHub Desktop.
Save nazarsa/7204d0e4ab41961ec3ffa1b184d996a9 to your computer and use it in GitHub Desktop.
mongo db insert
# mongoinsert.py
from pymongo import MongoClient
client = MongoClient('mongodb://localhost:27017/')
# data base name : 'mongodb-1'
db = client['mongodb-1']
import datetime
myrecord = {
"title" : "Mongo Insert",
"tags" : ["MongoDB", "PyMongo", "Snippet"],
"date" : datetime.datetime.utcnow()
}
record_id = db.mytable.insert(myrecord)
print record_id
print db.collection_names()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment