从 mongodb 中从符合条件的数据中随机出指定大小的数据:
python
def db_random_data(type: int, size: int = 21):
dbRes = collection.aggregate([
{
"$match": {
"is_gzh_upload": {"$exists": False},
"type": type
}
},
{'$sample': {'size': size}}
])
res = list(dbRes)
return res