Python:添加文档(MongoDB二)
#!/usr/bin/env python# coding:UTF-8"""@version: python3.x@author:曹新健@contact: 617349013@qq.com@software: PyCharm@file: 1、添加文档.py@time: 2018/9/23 22:37"""from pymongo impo
·
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: 1、添加文档.py
@time: 2018/9/23 22:37
"""
from pymongo import MongoClient
#连接服务器
conn = MongoClient("localhost",27017)
#连接数据库
db = conn.mydb
#获取集合
collection = db.student
#添加文档
#collection.insert({"name":"cxj01","age":18,"gender":1,"address":"天津","isDelete":0})
collection.insert([{"name":"delcxj01","age":18,"gender":1,"address":"天津","isDelete":0},
{"name":"delcxj02","age":28,"gender":1,"address":"昆明","isDelete":0},
{"name":"delcxj03","age":118,"gender":0,"address":"月球","isDelete":0}])
#断开
conn.close()
更多推荐
所有评论(0)