问题描述
我正在使用 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 (将#修改为@)