[SERVER-77548] Validator fails for optional property "r" Created: 29/May/23  Updated: 21/Jun/23  Resolved: 21/Jun/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.3.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Zachary Smith Assignee: Yuan Fang
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

Create a collection with that validator, and try to insert a document without the property "r".

 

I am using the Node.js driver in case that is important.

Participants:

 Description   

I am using this validator:

{{{}}
  $jsonSchema: {
    bsonType: 'object',
    additionalProperties: true,
    properties: {
      r: {
        bsonType: 'string',
      },
    },
  },
}

 

This validator should allow me to insert a document that doesn't have the property "r", but when I try to insert a document without this property it fails.

 

However, if I change the "r" field to "ref", then I can insert documents without the "ref" field.



 Comments   
Comment by Yuan Fang [ 21/Jun/23 ]

Hi zachsmith.sa@gmail.com,

For this issue of nodejs driver we'd like to encourage you to start by asking our community for help by posting on the MongoDB Developer Community Forums.

If the discussion there leads you to suspect a bug in the MongoDB server, then we'd want to investigate it as a possible bug here in the SERVER project. 

Regards,
Yuan

Comment by Zachary Smith [ 01/Jun/23 ]

Hi,

The problem is that the nodejs driver errors when a type is specified for
the optional property, but that property isn't included in the document
being inserted.

Zach

Comment by Yuan Fang [ 01/Jun/23 ]

Hi zachsmith.sa@gmail.com ,

Thank you for your report. I've tested with the validator you provided on version 6.3.1 and I am able to insert a document that doesn't have the property "r". However, please note that I tested this using the Mongo shell, and I'm not sure if the Node.js driver behaves differently. In order for us to reproduce the exact issue you encountered, could you provide detailed steps and any error messages you encountered? This will help us investigate and address the problem effectively. Thank you!

Regards,
Yuan

Generated at Thu Feb 08 06:35:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.