Lab: Polymorphic Pattern


After a few trials I think I am having some problems with understanding the wording of the instructions in the lab covering Polymorphic Pattern.

Does “Across all documents, we will use two fields for name: first_name and last_name” mean we should aim to have these two fields in one place in the schema or should we have a pair of them in each documents in the array?

Similarly with the next task, we want it to be a unique field, what in this case does indicative field mean?

Thank you in advance.

Hi @dobro2014,

Thank you for posting this. We’ll work on making our instructions more clear in the future.

This description means “to have a pair of these fields in each document in the array”.
Does that answer your question?

is it like —

"first_name":  "<string>",
"last_name":  "<string>"

“first_name”:"< string >",
“last_name”: " < string> "

it is second one. Passed.

Yes, thank you, that makes it clear. I am still having issues with the lab though. I find the other tasks also a bit confusing or maybe there is something I don’t know about schema design in MongoDB and that is why I find it difficult.

Similarly to the first and last name the problems tells us that the recruiting_source field should be in each document in the array, but at the same time later it also says that we should create this field only when a document doesn’t have a program_affiliation field, which to me sounds like a contradiction. From my understanding the value of program_affiliation should be maybe referenced in the recruiting_source field, but I don’t know how that would work in Mongo. I am probably overthinking it in some way.

Also after thinking about it, I don’t understand why there should be a field for name and last name in each document in the array if this is a a case where we should be implementing a polymorphic pattern, so shouldn’t we be trying to avoid the repetition of certain fields?

For a long time I was replicating the same solution like it was presented in the video about polymorphic pattern with the people and addresses example, where in our lab case instead of address as the array we have recruiting_source as the array name.

UPDATE: I just checked the answer and I am not sure how the solution provided qualifies as a use of polymorphic pattern. It seems like we just duplicated a lot of fields and did not try to narrow the number of certain fields that can me simplified, where in the video I believe the example is a clear showcase of the pattern.

1 Like

Thank you for your feedback @dobro2014,

We’ll be updating this lab for future instances of the course to provide a more clear use case example for the polymorphic pattern.


Is there any update on this thread? It feels like I can strongly empathize with the OP (dobro2014), almost a month later. It could possibly save time for many people.




Please help me in this lab. What can I do to validate my schema?

For Chapter 4: Patterns (Part 2) Lab: Apply the Polymorphic Pattern
I use command: validate_m320 pattern_polymorphic --file pattern_polymorphic.json --verbose=2
The validation msg as below, all seem passed but last line reported as :Errors:
it made me confused. :wink: someone can lend some ideas where is the issue?
How can I find the specific error(s)?

Processing document: 1
… against solution: 1
The document passes validation

Processing document: 2
… against solution: 1
The document passes validation

Processing document: 3
… against solution: 1
The document passes validation

At least one of your solutions is not passing validation.

@suhank it means there’s an error.
See if this discussion helps.