Validation states "field was missing" despite them existing

Very new to MongoDB and tried to make a collection with validation, but I have kept trying and failing to insert some data into it for the first time. Lots of trial and error but continued failures, even from putting the data in via Compass, Motor, and web browser. Here’s the schema, test data I’ve tried inserting, and then the error I get from the web browser version of Atlas.

I just don’t understand what’s going wrong or where due to how new I am, so I would appreciate it if I could get an explanation as to what’s going wrong here. Thanks to anyone who attempts to help!

Schema

{
  required: [
    '_id',
    'date',
    'username',
    'cheatData'
  ],
  properties: {
    _id: {
      bsonType: 'long',
      title: 'User ID',
      description: 'Holds the SteamID64 of an entered user. Is a primary key. Required.'
    },
    date: {
      bsonType: 'date',
      title: 'Addition Date',
      description: 'Holds a MongoDB Date that represents the date and time that the data was added. Required.'
    },
    username: {
      bsonType: 'string',
      title: 'Username',
      description: 'The current username of a given user, obtained via Steam API. Required.'
    },
    aliases: {
      bsonType: 'array',
      title: 'Aliases',
      description: 'All past aliases of the user, obtained via Steam API.',
      items: {
        bsonType: 'string'
      }
    },
    friends: {
      bsonType: 'array',
      title: 'Friends',
      description: 'The current friends of the user, obtained via Steam API.',
      items: {
        bsonType: 'long'
      }
    },
    cheatData: {
      bsonType: 'object',
      title: 'Cheat Data',
      description: 'An object that contains what the user is logged as, reasons why if they\'re not innocent, and optional evidence links to prove they cheat. Required entries: flag, isBot.',
      required: [
        'flag, isBot'
      ],
      properties: {
        flag: {
          bsonType: 'string',
          title: 'Flag',
          description: 'What level of suspicion the user is at. Required.',
          'enum': [
            'innocent',
            'watched',
            'suspicious',
            'cheater'
          ]
        },
        isBot: {
          bsonType: 'bool',
          title: 'Is Bot',
          description: 'A simple boolean to say if the user is a bot. Required.'
        },
        infractions: {
          bsonType: 'array',
          title: 'Infractions',
          description: 'All possible or confirmed infractions/cheats the user has demonstrated employing. Should only be filled out if the flag is suspicious or cheater.',
          items: {
            bsonType: 'string'
          }
        },
        evidence: {
          bsonType: 'array',
          title: 'Evidence',
          description: 'All evidence that is used to prove the user is a cheater. Not required, heavily encouraged.',
          items: {
            bsonType: 'string'
          }
        }
      }
    },
    overrideName: {
      bsonType: 'string',
      title: 'Custom Name',
      description: 'Overrides the username when displayed on any data visualizer or displayer. Should be used if a cheater changes their name often.'
    }
  }
}

Test Data

{
  "_id": {
    "$numberLong": "76561198818675138"
  },
  "username": "test",
  "date": {
    "$date": {
      "$numberLong": "1685904702000"
    }
  },
  "aliases": [
    "test",
    "test the code"
  ],
  "friends": [
    {
      "$numberLong": "76561198818675136"
    },
    {
      "$numberLong": "76561198818675136"
    }
  ],
  "cheatData": {
    "flag": "innocent",
    "isBot": false
  },
  "overrideName": "hello"
}

Error
Document failed validation:

{
  "failingDocumentId": {
    "$numberLong": "76561198818675138"
  },
  "details": {
    "operatorName": "$and",
    "clausesNotSatisfied": [
      {
        "index": {
          "$numberInt": "0"
        },
        "details": {
          "operatorName": "$eq",
          "specifiedAs": {
            "required": [
              "_id",
              "date",
              "username",
              "cheatData"
            ]
          },
          "reason": "field was missing"
        }
      },
      {
        "index": {
          "$numberInt": "1"
        },
        "details": {
          "operatorName": "$eq",
          "specifiedAs": {
            "properties": {
              "_id": {
                "bsonType": "long",
                "title": "User ID",
                "description": "Holds the SteamID64 of an entered user. Is a primary key. Required."
              },
              "date": {
                "bsonType": "date",
                "title": "Addition Date",
                "description": "Holds a MongoDB Date that represents the date and time that the data was added. Required."
              },
              "username": {
                "bsonType": "string",
                "title": "Username",
                "description": "The current username of a given user, obtained via Steam API. Required."
              },
              "aliases": {
                "bsonType": "array",
                "title": "Aliases",
                "description": "All past aliases of the user, obtained via Steam API.",
                "items": {
                  "bsonType": "string"
                }
              },
              "friends": {
                "bsonType": "array",
                "title": "Friends",
                "description": "The current friends of the user, obtained via Steam API.",
                "items": {
                  "bsonType": "long"
                }
              },
              "cheatData": {
                "bsonType": "object",
                "title": "Cheat Data",
                "description": "An object that contains what the user is logged as, reasons why if they're not innocent, and optional evidence links to prove they cheat. Required entries: flag, isBot.",
                "required": [
                  "flag, isBot"
                ],
                "properties": {
                  "flag": {
                    "bsonType": "string",
                    "title": "Flag",
                    "description": "What level of suspicion the user is at. Required.",
                    "enum": [
                      "innocent",
                      "watched",
                      "suspicious",
                      "cheater"
                    ]
                  },
                  "isBot": {
                    "bsonType": "bool",
                    "title": "Is Bot",
                    "description": "A simple boolean to say if the user is a bot. Required."
                  },
                  "infractions": {
                    "bsonType": "array",
                    "title": "Infractions",
                    "description": "All possible or confirmed infractions/cheats the user has demonstrated employing. Should only be filled out if the flag is suspicious or cheater.",
                    "items": {
                      "bsonType": "string"
                    }
                  },
                  "evidence": {
                    "bsonType": "array",
                    "title": "Evidence",
                    "description": "All evidence that is used to prove the user is a cheater. Not required, heavily encouraged.",
                    "items": {
                      "bsonType": "string"
                    }
                  }
                }
              },
              "overrideName": {
                "bsonType": "string",
                "title": "Custom Name",
                "description": "Overrides the username when displayed on any data visualizer or displayer. Should be used if a cheater changes their name often."
              }
            }
          },
          "reason": "field was missing"
        }
      }
    ]
  }
}

Edited to include @Jack_Woehr’s fix

Maybe "isBot": false ?

1 Like

That did fix one issue, but the overarching problem still remains. Sure wouldn’t have caught it, thanks for the help!

Output still the same?

1 Like

So a combination of things has happened:

  1. I am Icarus and thought I fixed it upon seeing the below error, but was wrong.
  1. There’s a weird discrepancy between the App Services schema validator and literally everything else??

The AS validator states no errors:

However, if I attempt to use Compass, with the same pasted schema mind you:

I genuinely don’t understand this stuff, I’ll post the updated schemas, test files, and errors but this is truly pain inducing at this point.

Updated Schema

{
    "title": "userList",
    "required": [
        "_id",
        "date",
        "username",
        "cheatData"
    ],
    "properties": {
        "_id": {
            "bsonType": "string",
            "title": "User ID",
            "description": "Holds the Steam3 ID of an entered user. Is a primary key. Required."
        },
        "date": {
            "bsonType": "date",
            "title": "Addition Date",
            "description": "Holds a MongoDB Date that represents the date and time that the data was added. Required."
        },
        "username": {
            "bsonType": "string",
            "title": "Username",
            "description": "The current username of a given user, obtained via Steam API. Required."
        },
        "aliases": {
            "bsonType": "array",
            "title": "Aliases",
            "description": "All past aliases of the user, obtained via Steam API.",
            "items": {
                "bsonType": "string"
            }
        },
        "friends": {
            "bsonType": "array",
            "title": "Friends",
            "description": "The current friends of the user, obtained via Steam API.",
            "items": {
                "bsonType": "string"
            }
        },
        "cheatData": {
            "bsonType": "object",
            "title": "Cheat Data",
            "description": "An object that contains what the user is logged as, reasons why if they're not innocent, and optional evidence links to prove they cheat. Required entries: flag, isBot.",
            "required": [
                "flag",
                "isBot"
            ],
            "properties": {
                "flag": {
                    "bsonType": "string",
                    "title": "Flag",
                    "description": "What level of suspicion the user is at. Required."
                },
                "isBot": {
                    "bsonType": "bool",
                    "title": "Is Bot",
                    "description": "A simple boolean to say if the user is a bot. Required."
                },
                "infractions": {
                    "bsonType": "array",
                    "title": "Infractions",
                    "description": "All possible or confirmed infractions/cheats the user has demonstrated employing. Should only be filled out if the flag is suspicious or cheater.",
                    "items": {
                        "bsonType": "string"
                    }
                },
                "evidence": {
                    "bsonType": "array",
                    "title": "Evidence",
                    "description": "All evidence that is used to prove the user is a cheater. Not required, heavily encouraged.",
                    "items": {
                        "bsonType": "string"
                    }
                }
            }
        },
        "overrideName": {
            "bsonType": "string",
            "title": "Custom Name",
            "description": "Overrides the username when displayed on any data visualizer or displayer. Should be used if a cheater changes their name often."
        }
    }
}

Updated Test File Numero Uno y Dos
File 1 (Currently In Database):

{
    "_id": "[U:1:1341943403]",
    "date": {
        "$date": {
            "$numberLong": "1685904702000"
        }
    },
    "username": "OMEGATRONIC",
    "aliases": [
        "OMEGATRONIC"
    ],
    "friends": [
        "[U:1:1546566598]",
        "[U:1:1545378816]"
    ],
    "cheatData": {
        "flag": "cheater",
        "isBot": true,
        "infractions": [
            "cathook"
        ],
        "evidence": [
            "linkgoeshere"
        ]
    },
    "overrideName": "hello"
}

File 2:

{
    "_id": "[U:1:3333333333]",
    "date": {
        "$date": {
            "$numberLong": "1685904702001"
        }
    },
    "username": "OMEGATRONIC",
    "aliases": [
        "OMEGATRONIC"
    ],
    "friends": [
        "[U:1:1111111111]",
        "[U:1:2222222222]"
    ],
    "cheatData": {
        "flag": "cheater",
        "isBot": true,
        "infractions": [
            "cathook"
        ],
        "evidence": [
            "linkgoeshere"
        ]
    },
    "overrideName": "hello"
}

Error

{
    "failingDocumentId": "[U:1:3333333333]",
    "details": {
        "operatorName": "$and",
        "clausesNotSatisfied": [
            {
                "index": {
                    "$numberInt": "0"
                },
                "details": {
                    "operatorName": "$eq",
                    "specifiedAs": {
                        "title": "userList"
                    },
                    "reason": "field was missing"
                }
            },
            {
                "index": {
                    "$numberInt": "1"
                },
                "details": {
                    "operatorName": "$eq",
                    "specifiedAs": {
                        "required": [
                            "_id",
                            "date",
                            "username",
                            "cheatData"
                        ]
                    },
                    "reason": "field was missing"
                }
            },
            {
                "index": {
                    "$numberInt": "2"
                },
                "details": {
                    "operatorName": "$eq",
                    "specifiedAs": {
                        "properties": {
                            "_id": {
                                "bsonType": "string",
                                "title": "User ID",
                                "description": "Holds the Steam3 ID of an entered user. Is a primary key. Required."
                            },
                            "date": {
                                "bsonType": "date",
                                "title": "Addition Date",
                                "description": "Holds a MongoDB Date that represents the date and time that the data was added. Required."
                            },
                            "username": {
                                "bsonType": "string",
                                "title": "Username",
                                "description": "The current username of a given user, obtained via Steam API. Required."
                            },
                            "aliases": {
                                "bsonType": "array",
                                "title": "Aliases",
                                "description": "All past aliases of the user, obtained via Steam API.",
                                "items": {
                                    "bsonType": "string"
                                }
                            },
                            "friends": {
                                "bsonType": "array",
                                "title": "Friends",
                                "description": "The current friends of the user, obtained via Steam API.",
                                "items": {
                                    "bsonType": "string"
                                }
                            },
                            "cheatData": {
                                "bsonType": "object",
                                "title": "Cheat Data",
                                "description": "An object that contains what the user is logged as, reasons why if they're not innocent, and optional evidence links to prove they cheat. Required entries: flag, isBot.",
                                "required": [
                                    "flag",
                                    "isBot"
                                ],
                                "properties": {
                                    "flag": {
                                        "bsonType": "string",
                                        "title": "Flag",
                                        "description": "What level of suspicion the user is at. Required."
                                    },
                                    "isBot": {
                                        "bsonType": "bool",
                                        "title": "Is Bot",
                                        "description": "A simple boolean to say if the user is a bot. Required."
                                    },
                                    "infractions": {
                                        "bsonType": "array",
                                        "title": "Infractions",
                                        "description": "All possible or confirmed infractions/cheats the user has demonstrated employing. Should only be filled out if the flag is suspicious or cheater.",
                                        "items": {
                                            "bsonType": "string"
                                        }
                                    },
                                    "evidence": {
                                        "bsonType": "array",
                                        "title": "Evidence",
                                        "description": "All evidence that is used to prove the user is a cheater. Not required, heavily encouraged.",
                                        "items": {
                                            "bsonType": "string"
                                        }
                                    }
                                }
                            },
                            "overrideName": {
                                "bsonType": "string",
                                "title": "Custom Name",
                                "description": "Overrides the username when displayed on any data visualizer or displayer. Should be used if a cheater changes their name often."
                            }
                        }
                    },
                    "reason": "field was missing"
                }
            }
        ]
    }
}

Further Update:
Even if I removed the required arguments on a fresh off the printer collection, it still continues to error stating I have missing fields.

???

Are you saying one of those two files passes validation and the other does not?

I temporarily disabled validation through Compass by switching it to warn instead of error which let it go through, to let me test it with App Services’ schema validator. It passed the tests there, and the other file does as well.

Attempting to insert after switching back to error results in failure.

I went thru something like this once with MongoDB validation, and it turned out that I had spelled something 2 different ways in 2 different places. ISTR I looked at it for a week before I finally spotted it.