【发布时间】:2020-05-03 13:01:15
【问题描述】:
如何在 python flask mongodb 中向特定用户插入数据
{
"_id" : ObjectId("5e208aa1f86973bbd7db6e8a"),
"worker_name" : "user1",
"location" : "location1",
"detection" : [ ]
},
{
"_id" : ObjectId("5e208aa1f86973bbd7db6e8b"),
"worker_name" : "user2",
"location" : "location2",
"detection" : [ ]
}
上面是我的用户,我想在user1 detection列表中插入一些数据,下面是我尝试过的代码
def face_detection():
face_module = mongo.db.face_modules
user = mongo.db.users
stream_link = request.form['stream_link']
location = request.form['location']
camera = request.form['camera']
result = {
"location": location,
"stream_url": stream_link,
"worker_name": "user1",
"date": "1/1/2020",
"hour": "9",
"minute": "10",
"second": "25"
}
if user.find({"worker_name": result['worker_name']}).count() > 0:
update_user = user.detection.insert(result)
output = "user updated"
return jsonify({'result': output})
【问题讨论】:
-
那么你得到了什么错误?您的意思是使用
insert_one而不是insert? -
@GonzaloHernandez 我不知道我是烧瓶 python 的新手,我希望
result字典应该插入到user1检测列表中
标签: python python-3.x mongodb flask pymongo