Mongo DB Schema Validation Error Object is empty

I recently started working with Realm and decided to write my schemas on Realm’s UI, essentially using the JSON Schema Editor. Prior to using Realm, I used to do this validation through mongoose on a dedicated server, using javascript. However, given Realm’s cloud functions, and serverless nature, I opted for just creating the JSON schema on Realm’s UI.

However, when I attempt to update or create a document using a cloud function, and schema validation fails, I get an empty error object, with no information on where or why it failed Schema validation.

This seemed interesting, because the collection insert, update, etc, functions do create a writeError object, when they fail, according to MongoDB’s documentation

Note: the reason why I want the writeError Object info, is that debugging is easier, and I can chain cloud functions together, and create error stack traces.

Below is small example of my dilemma:


    "bsonType": "object",
    "properties": {
        "_id": {
            "bsonType": "string"
        "account_type": {
            "bsonType": "string",
            "enum": [
            "maxLength": 300,
            "minLength": 0

Sample Cloud Function:

export = async function (){
      const collection ="mongodb-atlas").db("Development").collection("users");
      const user_id =;
      try {
        //failing condition since account_type cannot be parent
        const result = await collection.insertOne({_id:  user_id, account_type: "parent"});
        return result
      } catch (e) {
        const error = new Error ( "could not create a new user")
        error.metadata = e
        return error

Returned Error:

So my question is:

Can I get a more detailed error message back? If so, what should I add/change to get this writeError object?

I went thru this a year or two ago.
The log messages were equally unhelpful for validation errors.
I stared at my validation code for quite a while before I found the misspelling :slight_smile:
MongoDB knows about this. Maybe they’ve actually fixed it, I’m not expert on their various versions.
Maybe @Stennie knows.