[SERVER-24846] disallow extra fields when validating documents Created: 30/Jun/16  Updated: 06/Dec/22  Resolved: 24/Mar/18

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

Type: Improvement Priority: Major - P3
Reporter: Ciprian Trusca Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-30191 Add JSON Schema support for document ... Closed
Related
Assigned Teams:
Query
Participants:

 Description   

I would like to be able to validate the documents so that no extra fields, beyond the ones already declared. For example if i have a schema like this :

 
    "group1.a": {
      "$type": "int"
    },
    "group1.b": {
      "$type": "int"
    }

I would like the following document to fail:

    {
       "group1": {
          "a": 1,
          "b": 2,
          "c": 3
       }
    }



 Comments   
Comment by Asya Kamsky [ 24/Mar/18 ]

Available via $jsonSchema as of 3.6.0.

Comment by Asya Kamsky [ 24/Mar/18 ]

This was enabled via SERVER-30191 which allows json schema syntax in document validation - json schema allows specifying that only explicitly described keys are allowed.

Comment by Asya Kamsky [ 28/Nov/16 ]

kkumarc@gmail.com this ticket is tracking the ability to disallow any new fields (ones that are not explicitly allowed) from being inserted.

The only way I can see it being useful for your use case is if you set validationAction to "warn" and then grep the logs for fields not in the validator document.

Comment by KRISHNA KUMAR [ 23/Nov/16 ]

Hi,
We are also interested in this feature. We need to know if a new field is added to the mongoDB data model so that we can modify the GraphQL schema cache accordingly.
Thanks!

regards
Krishna

Comment by Kelsey Schubert [ 02/Sep/16 ]

Hi hbalint,

Thank you for your interest in contributing to MongoDB. Please be aware that we have recently entered our stabilization period in preparation for the release of MongoDB 3.4. We our doing our best to freeze new feature development in order to focus on quality and performance, and to ensure that downstream work (such as that required for the documentation and drivers) can be completed.

We haven't had a chance yet to discuss this improvement request, and will update this ticket when we have a better idea of how this functionality can be best implemented and whether it is something we want to incorporate into the product at this time.

My recommendation would be to wait for additional input before beginning work on a patch. In the meantime, you can take the first step of signing the contributor agreement.

Kind regards,
Thomas

Comment by Bálint Horváth [ 02/Sep/16 ]

Hi guys,

I'm also really interested in it and its future possibilities and I'm considering contribution... Unfortunately I can't see the private comments. Is there any news or an alternate issue about it or this is the primary one? Is there any concept/plan for it? Any other links to other discussions maybe? In my opinion, document shouldn't fail by default even if validator is defined but option would be very useful to define allowed fields (mostly because of multi-level documents which makes more difficult to do validation on higher level than MongoDB with proper security and performance).

(Currently I'm designing a system which is partly relies on the mongo validator. Already a really cool feature.)

Thanks,
Bálint

Comment by Ramon Fernandez Marina [ 30/Jun/16 ]

Thanks for your report cip123; I was convinced this functionality had been requested already, but I can't seem to find the ticket so I'm sending this to the Integration team for consideration.

Regards,
Ramón.

Generated at Thu Feb 08 04:07:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.