0

My code for the PUT method,

@app.route('/update_doc/<id>', methods=["PUT"])
def update_method(id):
    body = request.get_json()
    updated_document = db_collection.objects.get(id=id).update(**body)
    #document.modify(**body)
    return 'success', 200

I am getting the following error,

 Traceback (most recent call last):
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 2088, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 2073, in wsgi_app
    response = self.handle_exception(e)
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 2070, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 1515, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 1513, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/flask/app.py", line 1499, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/home/configcar_it/Documents/k8s/ec2_mongodb/ec2_mongodb_validator.py", line 119, in update_method
    store = Store_collection.objects.get(id=id).update(**body)
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/document.py", line 610, in update
    return self._qs.filter(**self._object_key).update_one(**kwargs)
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/queryset/base.py", line 631, in update_one
    return self.update(
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/queryset/base.py", line 555, in update
    update = transform.update(queryset._document, **update)
  File "/home/configcar_it/anaconda3/envs/ec2_mongodb/lib/python3.9/site-packages/mongoengine/queryset/transform.py", line 301, in update
    field = cleaned_fields[-1]
IndexError: list index out of range

The remaining Post, Delete, Get methods are working. I am giving the input through the postman.

Delete method

@app.route('/stores/<id>', methods=['DELETE'])
def delete_doc(id):
    stores = Store_collection.objects.get(id=id).delete()
    return 'successfully deleted.', 200
4

1 回答 1

0

通过互联网浏览后,我发现我在我的 MongoDB 数据库中将字段名称指定为“类型”。了解这一点后,我更改了“类型”->“类型”。现在它工作正常。我通过阅读以下 GitHub 问题来理解这一点——> https://github.com/MongoEngine/mongoengine/issues/1194

此外,同样的问题类似于“大小”这个词。希望这可能对某人有所帮助。

于 2021-07-06T11:06:42.890 回答