Nested Documents vs. Nested BaseModels on creation? #678
Unanswered
JoshJarabek7
asked this question in
Question
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Three-parter question:
P1:
I've been using BaseModel for the nested models in the root parent document, however, I'm a little confused on indexing the subdocuments.
Can I use Beanie Document models instead of the BaseModel models for the nested models and define the indices that way?
I've seen a couple examples of Documents inside of Documents in the beanie docs, but can I index via the nested Documents?
If yes, then...
P2:
I'm looking at the inheritance section of the Beanie documentation and it's unclear if saving the root document creates MongoDB documents for all of its children or not.
If I save the root document, does that create separate documents for all of the nested documents? Because I'm essentially just wanting to nest beanie Documents inside of beanie Documents to simplify indexing and methods for nested documents. I definitely do not want to create a separate document in MongoDB for each beanie Document in this tree.
P3:
If saving the parent document doesn't create MongoDB documents for the nested beanie documents, do I need to initialize the nested document models on startup?
TLDR:
How do I define indices for nested models in a root document without creating documents in MongoDB for the nested document models on save?
Beta Was this translation helpful? Give feedback.
All reactions