如何使用 pymongo 手动创建 DBRef?

发布于 2024-09-06 02:39:42 字数 382 浏览 17 评论 0原文

我想手动创建一个 DBRef,以便可以向其中添加一个附加字段。但是,当我尝试传递以下内容时:

{'$ref': 'projects', '$id': '1029412409721', 'project_name': 'My Project'}

Pymongo raises an error:

pymongo.errors.InvalidName: key '$id' must not start with '$'

It might not be the pymongo Reserve the $ for thespecial key,这让我想知道是否可以做我想做的事情想做什么?

I want to create a DBRef manually so that I can add an additional field to it. However, when I try to pass the following:

{'$ref': 'projects', '$id': '1029412409721', 'project_name': 'My Project'}

Pymongo raises an error:

pymongo.errors.InvalidName: key '$id' must not start with '

It would seem that pymongo reserve the $ for the special key, leading me to wonder if it is even possible to do what I'm trying to do?

It would seem that pymongo reserve the $ for the special key, leading me to wonder if it is even possible to do what I'm trying to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情出卖 2024-09-13 02:39:42

可能不想像这样手动创建它们,因为 DBRef 中的键需要排序。我们可以添加一个选项来创建带有自定义 kwargs 的 DBRef 实例,这将解决您的问题。如果您为此提交一个 jira,我们应该能够在即将发布的版本中将其发布。

Probably don't want to be creating them manually like that, since keys in DBRefs need to be ordered. We could add an option to create a DBRef instance w/ custom kwargs though, which would solve your problem. If you file a jira for this we should be able to get it out in an upcoming release.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文