从MongoDB的DictField中删除一列[Flask + MongoEngine] [英] Removing a column from a DictField in MongoDB [Flask + MongoEngine]

查看:475
本文介绍了从MongoDB的DictField中删除一列[Flask + MongoEngine]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从DictField(在本例中为content)中删除所有文档中的特定列(在本例中为Paper ID)。相应的mongo-shell脚本也是这样的:

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

如何使用MongoEngine编写同样的东西,假设我的模型类名为JListInputFile。同样的文档不是很有帮助。

解决方案

我认为您所遇到的问题是字段名称中的空格,意味着您无法将其作为关键字参数例如:

  JListInputFile.objects.update(unset__content__Paper ID = 1)

使用字典kwargs工作:

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


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.

解决方案

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

这篇关于从MongoDB的DictField中删除一列[Flask + MongoEngine]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆