具有父\u id的Mongodb架构

具有父\u id的Mongodb架构,mongodb,mongoose,Mongodb,Mongoose,我需要做带有答案的消息模式。我试着用父母的身份证,但没用 var messageSchema = new Schema({ _id : {type : String}, sender : { type : String}, reciver : {type : String}, text : {type : String}, answer:[{ parent_id : _id, texto :{type:String} }] })) 当我写带有答案的帖子时,总是创建一个needr

我需要做带有答案的消息模式。我试着用父母的身份证,但没用

var messageSchema = new Schema({
_id : {type : String},
sender : { type : String},
reciver : {type : String},
text : {type : String},
answer:[{
    parent_id : _id,
    texto :{type:String}
}]
}))

当我写带有答案的帖子时,总是创建一个needrandom id,而不是_id。
谢谢

您想将哪个
\u id
分配给
家长\u id
?这是另一条消息吗?我希望_id与父id相同。您希望文档id(
_id
)作为其所有子文档的属性存储在该应答数组中吗?目的是什么?这是可能的,但似乎完全没有必要。但您将有一条消息和各种答案,所有这些答案我都需要它们具有相同的父项。答案是否多于
texto
属性?由于它们都将位于同一文档的
答案
数组中,它们不能只访问文档ID吗?如果您只是在寻找一种方便的方法,那么可以对子文档使用一种方法,以避免在同一文档中重复相同的数据。