gpt4 book ai didi

mongodb - 迁移到 0.8 后如何修复 mongoengine 取消引用错误?

转载 作者:可可西里 更新时间:2023-11-01 10:01:14 26 4
gpt4 key购买 nike

我刚刚升级了 mongoengine,但现在出现错误。目前,模型定义如下:

class Descriptor(Document):
root = ReferenceField(DescriptorNode, required=True)
(..)

class DescriptorNode(Document):
channel = ReferenceField(Channel, required=True)
(..)

class Channel(Document):
(..)

使用 DBRef = True,这是我在 mongoengine==0.7.10 中使用的当前代码:

descriptor =  Descriptor.objects.get(id = xxxx)
channel = descriptor.root.channel

我选择删除 DBRef = True 以便迁移到 mongoengine==0.8.1,然后重建数据库。

现在我收到这个错误:

channel = descriptor.root.channel
AttributeError: channel
/site-packages/bson/dbref.py Line:88

我尝试了 select_related(),但似乎没有什么能正常工作。

描述符:

{
"_id" : ObjectId("51ae3f6ba2aa1c0a32998952"),
"created_date" : ISODate("2013-06-04T19:26:35.630Z"),
"modified_date" : ISODate("2013-06-05T12:45:55.570Z"),
"sequence" : 843174,
"groups" : [ ],
"name" : "desktop-BR",
"root" : ObjectId("51ae3f6ba2aa1c0a329988b0"),
"tree_hash" : "97e3716db74543e66a11405e9e04185452183ac1"
}

描述符节点:

{
"_id" : ObjectId("51ae3f6aa2aa1c0a3299885a"),
"channel" : ObjectId("51ae0f06a2aa1c0a327f3958"),
"created_date" : ISODate("2013-06-04T19:26:34.235Z"),
"groups" : [ ],
"is_prioritized" : false,
"is_published" : true,
"modified_date" : ISODate("2013-06-05T12:46:02.704Z"),
"order" : 0,
"sequence" : 842926
}

最佳答案

你有没有和例子做的一样?

首先,将 DBRef = True 更改为 DBRef = False。其次,手动迁移:

for d in Descriptor.objects():
d.root = d.root
d.save()

for d in DescriptorNode.objects():
d.channel = d.channel
d.save()

关于mongodb - 迁移到 0.8 后如何修复 mongoengine 取消引用错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16927424/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com