[COMPASS-7285] Problem in validation under the collection Created: 01/Oct/23  Updated: 27/Oct/23  Resolved: 03/Oct/23

Status: Closed
Project: Compass
Component/s: None
Affects Version/s: None
Fix Version/s: No version

Type: Bug Priority: Blocker - P1
Reporter: Punit Mann Assignee: Unassigned
Resolution: Works as Designed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

OS: Windows 11
Python / Python Versions: Python 3.11.5


Attachments: PNG File Screenshot (9).png    
Documentation Changes: Not Needed

 Description   

Problem Statement/Rationale

In MongoDB Compass, I am encountering an issue with validation in a particular collection. When I define a validation rule, save it, and then update the collection, it consistently shows "Failed validation," even when the data matches the validation rule. 
Example:
This is my original data under the collection
{
  "_id": {     "$oid": "6513d54145b4ff5f40df58e3"   },
  "name": "Mug"
}
I am validating as per this 
{
  name: {     type: 'string'   }
}
As the name is string but it shows me every validation under the Failed Validation.

Please be sure to attach relevant logs with any sensitive data redacted.

{"t":\{"$date":"2023-10-01T16:59:59.792+05:30"}

,"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn5","msg":"client metadata","attr":{"remote":"127.0.0.1:59272","client":"conn5","doc":{"application":

{"name":"MongoDB Compass"}

,"driver":{"name":"nodejs","version":"6.0.0"},"platform":"Node.js v18.16.1, LE","os":{"name":"win32","architecture":"x64","version":"10.0.22621","type":"Windows_NT"}}}}

{"t":\{"$date":"2023-10-01T16:59:59.797+05:30"}

,"s":"I", "c":"NETWORK", "id":6788700, "ctx":"conn5","msg":"Received first command on ingress connection since session start or auth handshake","attr":{"elapsedMillis":5}}

{"t":\{"$date":"2023-10-01T16:59:59.798+05:30"}

,"s":"I", "c":"COMMAND", "id":5324200, "ctx":"conn5","msg":"CMD: collMod","attr":{"cmdObj":{"collMod":"products","validator":{"name":{"type":"string"}},"validationLevel":"strict","validationAction":"error"}}}

{"t":\{"$date":"2023-10-01T16:59:59.800+05:30"}

,"s":"I", "c":"REPL", "id":7360104, "ctx":"conn5","msg":"Wrote oplog entry for collMod","attr":{"namespace":"aggregation_test.$cmd","uuid":{"uuid":{"$uuid":"e338876b-45e2-4e59-b53f-9c7bbbe1dcff"}},"opTime":{"ts":{"$timestamp":{"t":0,"i":0}},"t":-1},"object":{"collMod":"products","validator":{"name":{"type":"string"}},"validationLevel":"strict","validationAction":"error"}}}

Steps to Reproduce

How could an engineer replicate the issue you’re reporting?To reproduce the issue:

  1. Open MongoDB Compass.
  2. Select a collection.
  3. Define a validation rule, such as:
    {
      "name": {     "type": "string"   }

    }

  4. Save the validation rule.
  5. Update the collection.

Expected Results

What do you expect to happen?
- I expect the validation to pass as the "name" field is a string, and it should match the defined validation rule.

Actual Results

What do you observe is happening?
- Currently, the validation shows "Failed validation" even when the data complies with the validation rule.



 Comments   
Comment by Rhys Howell [ 03/Oct/23 ]

Hi punitmann9599@gmail.com 
You'll have to specify a schema object in a format like the following to use Compass' schema validation:
{
  $jsonSchema: {
    bsonType: 'object',
    required: [
      'name'
    ],
    properties: {
      name:

{         bsonType: 'string',         description: 'name must be a string'       }

    }
  }
}

Here's some more documentation:
https://www.mongodb.com/docs/manual/core/schema-validation/specify-validation-level/#steps--use-strict-validation 

I do understand how it's not quite intuitive - we aren't giving many clues as to what the format should be in this validation tab. It's something we'll have to look into improving the user experience of down the line. cc julia.oppenheim@mongodb.com  

Comment by Prof Moriarity [ 03/Oct/23 ]

I am using arch , and I am having the same issue . I opens and like after 10 secs , a white screen is displayed and it stops working.

Comment by PM Bot [ 01/Oct/23 ]

Hello punitmann9599@gmail.com, thank you for reaching out to us! The team will review your issue and get back to you soon as soon as possible.

Please review your issue to ensure you've included your environment details and have attached relevant logs (with any sensitive data redacted), so that we're best able to provide you a timely and thorough response. Thanks again!

Generated at Wed Feb 07 22:46:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.