test_db.py 582 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env python
  2. # -*- encoding: utf-8 -*-
  3. '''
  4. @Author : liuyuqi
  5. @Contact : liuyuqi.gov@msn.cn
  6. @Time : 2019/08/11 08:52:06
  7. @Version : 1.0
  8. @License : (C)Copyright 2019
  9. @Desc : mongo操作
  10. '''
  11. import pymongo
  12. client = pymongo.MongoClient("mongodb://admin:password@localhost:27017/")
  13. db_juejin = client.juejin_date
  14. student1 = {
  15. 'id': '20170101',
  16. 'name': 'Jordan',
  17. 'age': 20,
  18. 'gender': 'male'
  19. }
  20. result = db_juejin.students.insert(student1)
  21. res1=db_juejin.students.insert_one(student1)
  22. res2=db_juejin.students.find({})
  23. print(res1.inserted_id)