pymongo使用方法

连接MongoDB
    连接MongoDB我们需要使用PyMongo库里面的MongoClient,一般来说传入MongoDB的IP及端口即可
client = pymongo.MongoClient(host='127.0.0.1', port=27017)
# 指定数据库
# MongoDB中还分为一个个数据库,我们接下来的一步就是指定要操作哪个数据库
db = client['tencent']
# 指定集合
# MongoDB的每个数据库又包含了许多集合Collection,也就类似与关系型数据库中的表,
collection = db.students
或collection = db['students']
student = {
    'id''20170101',
    'name''Jordan',
    'age'20,
    'gender''male'
}
result = collection.insert(student)
print(result)
原文地址:https://www.cnblogs.com/liubosong/p/10339613.html