Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Prido's avatar
Level 2

Nested doc in MongoDb

hi all, is it best to use mongo db in the following way. i have data that can be as follows:

//message
{
id: string,
conversation_id: string,
type: 'image' | 'document' | 'text' | 'buttonReply',
text: string,
data: object,
reply_msg_id: string,
}

the data object can have a different structure depending on the type field
this can grow depending on the type field in message
//data obj
{
media_link: string,
button_reply: {
id: string,
title: string
}
}

is it ok to save as nested doc in mongo or to create referencing models?

0 likes
0 replies

Please or to participate in this conversation.