Lab: Polymorphic pattern - ambiguous

I’m struggling to understand the requirements for this lab, similar to this previous student.

The requirements I’m struggling with are

  • Across all documents, we will use a field called recruiting_source as the indicative field for the document shape.
  • In documents that already have an existing program_affiliation field, we will use the value of this field as the recruiting_source.
  • In documents that don’t have program_affiliation, we will add a new field called recruiting_source.

So, are we adding a new field called recruiting_source to all 3 schemas regardless of whether they have a program_affiliation field? Or are we only adding recruiting_source to schemas which don’t have a program_affiliation field?

I think the first makes more sense, if we’re using recruiting_source to determine the schema of a document, then it needs to be in all documents regardless of schema, unless we want to fall back to a second field to determine the schema if the first field doesn’t exist. But I’ve tried both and neither seems to be correct. This is the output from the validation tool, which itself is a bit confusing:

Answer Filename: C:/Users/Simon/Documents/Mongo University/M320/pattern_polymorphic.json
The document passes validation

Errors:
At least one of your solutions is not passing validation.

It passes validation but it also fails validation?

I know this isn’t caused by badly formed JSON, as I tried removing a comma to make it badly formed and got a different message from the validator:

Errors - Invalid JSON format in file:
  pattern_polymorphic.json

And I’m fairly sure I’ve implemented the other two requirements correctly:

All documents should indicate whether an offer was extended via the extend_offer field.

Easy enough, I assume this is supposed to be a string as per the one schema which already contains this field?

Across all documents, we will use two fields for name: first_name and last_name.

Presumably these fields are meant to be at the root of the document, rather than fields of a child “name” document, as per the answer in the linked topic?

And the document I’m validating, because it contains 3 schemas, should be of the form…

[{...},{...},{...}]

… where each of the 3 objects in the array is one schema?

I’m hoping this is some schoolboy error in the way that multiple schemas are expressed in a single file (I notice all the previous labs are validating only one schema), which someone with more experience of schema validation than me will be able to guide me on.

Thank you

Simon

Simon,

you are right about the overall shape of the solution being an array of 3 sub-documents, in the form of:

[{...},{...},{...}]

Would you paste your solution in one of the on-line JSON validators like: https://jsonlint.com/

They may be a little more helpful than our validators to help you identify the syntax error.

Regards,
Daniel.

jsonlint.com also tells me that my JSON is well-formed, as did Visual Studio. So if the overall shape of my array is correct, then one or more of my documents is missing a field, or has an extra field, or has a field with the wrong name or value.

Could you answer the question about the ambiguity around the recruitment_source field please?

In case anyone stumbles across this topic, go here to read more: