Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

DOCSP-50472: schema validation #3400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
rustagir merged 9 commits into mongodb:5.x from rustagir:DOCSP-50472-jsonSchema-method
Jun 6, 2025

Conversation

@rustagir
Copy link
Contributor

@rustagir rustagir commented Jun 5, 2025
edited
Loading

@rustagir rustagir marked this pull request as ready for review June 5, 2025 20:30
@rustagir rustagir requested a review from a team as a code owner June 5, 2025 20:30
Copy link
Contributor

@mongoKart mongoKart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some small things then LGTM

Comment on lines +124 to +125
- ``Schema::create()``: When creating a new collection
- ``Schema::table()``: When updating collection properties
Copy link
Contributor

@mongoKart mongoKart Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: can you only implement schema validation when using these methods for these specific purposes? or is the info after the colons just a reminder of the method's purpose?

Copy link
Collaborator

@paulinevos paulinevos Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the only two methods in Laravel's Schema that accept a callback to alter columns, so you can only implement schema validation on either creating a collection or updating it.

rustagir reacted with thumbs up emoji
- ``Schema::table()``: When updating collection properties

After you implement schema validation, the server allows you to run only
those write operations which follow the validation rules. Use schema
Copy link
Contributor

@mongoKart mongoKart Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that/which

Suggested change
those write operations which follow the validation rules. Use schema
those write operations that follow the validation rules. Use schema

rustagir reacted with thumbs up emoji
Comment on lines 127 to 130
After you implement schema validation, the server allows you to run only
those write operations which follow the validation rules. Use schema
validation to restrict data types and value ranges of document fields in
a specified collection.
Copy link
Contributor

@mongoKart mongoKart Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: i wonder if the connection between these two sentences would be clearer if you switched them. something like:

Suggested change
After you implement schema validation, the server allows you to run only
those write operations which follow the validation rules. Use schema
validation to restrict data types and value ranges of document fields in
a specified collection.
You can use schema validation to restrict data types and value ranges of document fields in
a specified collection. After you implement schema validation, the server allows you to run only
those write operations which follow the validation rules.

rustagir reacted with thumbs up emoji
Copy link
Contributor Author

@rustagir rustagir Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

Comment on lines 132 to 138
Before creating a collection with schema validation rules, you must
define a JSON schema.

The schema is a JSON object that contains key-value pairs
specifying the validation rules for your collection. At the top level,
this object must include a ``$jsonSchema`` object. The ``$jsonSchema``
object can include the following fields:
Copy link
Contributor

@mongoKart mongoKart Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S: break up paragraphs differently. could also then remove first 'JSON'

Suggested change
Before creating a collection with schema validation rules, you must
define a JSON schema.
The schema is a JSON object that contains key-value pairs
specifying the validation rules for your collection. At the top level,
this object must include a ``$jsonSchema`` object. The ``$jsonSchema``
object can include the following fields:
Before creating a collection with schema validation rules, you must
define the schema.
A schema is a JSON object that contains key-value pairs
specifying the validation rules for your collection.
At the top level, this object must include a ``$jsonSchema`` object. The ``$jsonSchema``
object can include the following fields:

Copy link
Contributor Author

@rustagir rustagir Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed this paragraph per PV suggestion

Comment on lines 140 to 142
- ``title``: Sets an optional title for the schema.
- ``required``: Specifies a list of required fields for each document in your collection.
- ``properties``: Sets property requirements for individual fields.
Copy link
Contributor

@mongoKart mongoKart Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I: no periods

Suggested change
- ``title``: Sets an optional title for the schema.
- ``required``: Specifies a list of required fields for each document in your collection.
- ``properties``: Sets property requirements for individual fields.
- ``title``: Sets an optional title for the schema
- ``required``: Specifies a list of required fields for each document in your collection
- ``properties``: Sets property requirements for individual fields

Copy link
Contributor Author

@rustagir rustagir Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this text

This example demonstrates how to pass a JSON schema to the
``jsonSchema()`` method when creating a collection. The schema
validation specifies that documents in the ``pilots`` collection must
contain the ``license_number`` field with an integer value between
Copy link
Contributor

@mongoKart mongoKart Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

S:

Suggested change
contain the ``license_number`` field with an integer value between
contain the ``license_number`` field, and the field must have an integer value between

rustagir reacted with thumbs up emoji
Copy link
Contributor Author

@rustagir rustagir Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to a list


The schema is a JSON object that contains key-value pairs
specifying the validation rules for your collection. At the top level,
this object must include a ``$jsonSchema`` object. The ``$jsonSchema``
Copy link
Collaborator

@paulinevos paulinevos Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$jsonSchema doesn't need to be included in the schema argument (see the example). Since the method is Blueprint::jsonSchema, the '$jsonSchema' operation is already implied.

So this documentation may be valid for MongoDB server but not for Laravel usage

Copy link
Collaborator

@paulinevos paulinevos Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh also! Since this is PHP, the schema argument is not an object, but an associative array.

rustagir reacted with thumbs up emoji
this object must include a ``$jsonSchema`` object. The ``$jsonSchema``
object can include the following fields:

- ``title``: Sets an optional title for the schema.
Copy link
Collaborator

@paulinevos paulinevos Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we actually include this documentation? Seems to me the $jsonSchema operation is covered by the Mongo server docs. The Laravel ORM passes the schema through as is. I think specifying allowed fields here puts us in a situation of having to update this documentation when Mongo server specs change, when the user could just use the Mongo server docs as the single source of truth for jsonSchema usage.

Copy link
Contributor Author

@rustagir rustagir Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense - I'll cut out some of this text and apply the suggestions from your prev comment.

Copy link
Collaborator

@paulinevos paulinevos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! 🙏

@rustagir rustagir merged commit 5fe1f5d into mongodb:5.x Jun 6, 2025
71 checks passed
@GromNaN GromNaN added this to the 5.5 milestone Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@paulinevos paulinevos paulinevos approved these changes

@norareidy norareidy norareidy approved these changes

@mongoKart mongoKart mongoKart approved these changes

@lindseymoore lindseymoore Awaiting requested review from lindseymoore lindseymoore is a code owner automatically assigned from mongodb/laravel-docs

Assignees

No one assigned

Labels

Projects

None yet

Milestone

5.5

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /