1)首先先安装第三方库
pip install pymongo ‐i https://pypi.tuna.tsinghua.edu.cn/simple
2)使用Python脚本模拟较大量数据
import pymongo
from uuid import uuid4
import random
conn_str = "mongodb://localhost:27017/"
client = pymongo.MongoClient(conn_str)
#列出所有的数据库
print(client.list_database_names())
#创建geodata数据库
db = client["geo"]
coll = db["address"]
ls = []
for i in range(1000000):
temp = {
"name":str(uuid4()),
"x":random.randint(100,180),
"y":random.randint(0,90),
"iphone":"13569841651"
}
ls.append(temp)
if (i + 1) % 4000 == 0:
coll.insert_many(ls)
ls.clear()
print("已经插入完毕")
就可以向mongodb中插入数据了