#!/usr/bin/env python # -*- encoding: utf-8 -*- ''' @Author : liuyuqi @Contact : liuyuqi.gov@msn.cn @Time : 2019/08/11 08:52:06 @Version : 1.0 @License : (C)Copyright 2019 @Desc : mongo操作 ''' import pymongo client = pymongo.MongoClient("mongodb://admin:password@localhost:27017/") db_juejin = client.juejin_date student1 = { 'id': '20170101', 'name': 'Jordan', 'age': 20, 'gender': 'male' } result = db_juejin.students.insert(student1) res1=db_juejin.students.insert_one(student1) res2=db_juejin.students.find({}) print(res1.inserted_id)