import random as rand
from faker import Faker
faker=Faker("zh_cn")
from pymongo import MongoClient
#client = MongoClient()
client = MongoClient('localhost', 27017)
# 创建数据库-集合
database = client.student
collection = database.student_faker
# 向集合中增加数据:利用假数据向其中添加10条数据
for i in range(0,100000):
collection.insert_one(
{'name': faker.name(),'age':rand.randint(18,22),'student':rand.choice(["False","True"]),'address':faker.city()},
)
for i in collection.find():
print(i)
print("-------------------------------------------------")
MongoDB for Python--使用python向mongodb数据表中添加多个假数据
最新推荐文章于 2023-04-23 15:54:26 发布