What decides the type of value for a path?
It relates mainly to what kind of data the path will hold, and if we are being picky, we could even watch for the size depending on what type of values the database accepts. Talking about MongoDB using Mongoose, we can work with
Strings if it is a name, an address, a sentence, a word…
Numbers commonly used for years, ages, serial numbers that do not involve other characters, amount of things, prices…
Date for full month day year (commonly in this format:
Boolean when it needs a confirmation, like in a students collection you can have a path
has_passed that will be true or false depending on how the student performed.
Mixed accepts an object that can have multiple types in itself, for example, our previous students collection can have a parent_info path with an object that contains a parent_name(
String) and a phone_number(
Array it could be in case of a person having various aliases (
String array), or the years a student has been in the school (
As we can see, the type will depend on the value that will be stored in the path, and so it tends to be a developer’s decision when structuring the schema.