Anand Sainath
Anand Sainath

Reputation: 1807

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

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.

Upvotes: 0

Views: 1492

Answers (1)

Ross
Ross

Reputation: 18111

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})

Upvotes: 1

Related Questions