Removing a column from a DictField in MongoDB [Flask + MongoEngine]

好久不见. 提交于 2019-12-08 10:10:39

问题


I need to remove a particular column (in this case "Paper ID") from a DictField (in this case "content") in all documents. The corresponding mongo-shell script for the same is

db.list_input_file.update({},{$unset:{"content.Paper ID":1}}, false, true);

How do I write the same thing using MongoEngine assuming that my model class is named JListInputFile. The documentation for the same isn't very helpful.


回答1:


I think the issue you are having is a space in the field name meaning you can't pass it as a keyword argument eg:

JListInputFile.objects.update(unset__content__Paper ID=1)

Does using a dictionary kwargs work:

JListInputFile.objects.update(**{"unset__content__Paper ID": 1})


来源:https://stackoverflow.com/questions/26151632/removing-a-column-from-a-dictfield-in-mongodb-flask-mongoengine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!