Created
          November 15, 2016 15:47 
        
      - 
      
 - 
        
Save nazarsa/7204d0e4ab41961ec3ffa1b184d996a9 to your computer and use it in GitHub Desktop.  
    mongo db insert 
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | # 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