如何使用 pymongo 手动创建 DBRef?
我想手动创建一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能不想像这样手动创建它们,因为 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.