python: storing the data to mongodb

 Mongodb need to understand the basic operation of the local data insertion

# ! / Usr / bin / env python 
# - * - Coding: UTF-8 - * - 

"" " in python script, import the file into the database
 " "" 

from pymongo Import MongoClient 

MONGO_URL = " MongoDB: // localhost : 27017 "    # How to hnow 
MONGO_DB = " Test " 
MONGO_TABLE = " DAY1 " 

Client = MongoClient (MONGO_URL)    # generates mongodb target 
DB = Client [MONGO_DB] 

# # define the insertion function data 
DEF save_to_mongo (data):
     IF DB [MONGO_TABLE ]. INSERT(data):
        print("成功储存到MongoDB", data)
        return True 
    return False

data = {'name':'mike', 'score':99}
save_to_mongo(data) 

The results show :( inserted into the local database client: NoSQLBooster)

 

 

Guess you like

Origin www.cnblogs.com/lmt921108/p/11888928.html