为什么在 python 中 ReferenceField 不会自动取消引用

问题描述

我正在使用 flask_mongoengine 并且我已经创建了 2 个集合。

class User(db.Document):
    email = db.StringField(required=True)
    first_name = db.StringField(max_length=50)
    last_name = db.StringField(max_length=50)

class Post(db.Document):
    title = db.StringField(max_length=120,required=True)
    author = db.ReferenceField(User,dbref=True)

当我像这样在这些集合中插入一些数据时:

newUser = User(email=email,first_name=first_name,last_name=last_name).save()
post1 = Post(title=post,author=newUser).save()

当我尝试运行 Post.objects(title='something').first()

时无法访问用户数据

它给了我:

{
  "_id": {
    "$oid": "60cbdcc324bc32d4f079a405"
  },"author": {
    "$id": {
      "$oid": "60cbdcc324bc32d4f079a404"
    },"$ref": "user"
  },"title": "post-title"
}

我希望我的结果是这样的:

{
  "_id": {
    "$oid": "60cbdcc324bc32d4f079a405"
  },"author": {
    "email": "something@gmail.com","first_name": "John","last_name": "Doe"
  },"title": "post-title"
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...