问题
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