For example, say we want to make a rule that the summary field must be more that 10 characters to be valid and we'll use the $jsonSchema format to do it. We showed the editor's auto-completion earlier, but it does more than complete $ operators. Cancel will revert the rules document to how it was when we started editing. Notice the Update and Cancel buttons that appeared as soon as we started editing clicking Update will activate the new validation rules on the database. These rules aren't in place yet though, this is only a preview. There are no errors in our rules and the sample documents are back, complete with one document that passed and one that failed. If you are new to the JSON Schema Validation, We're looking at the AirBnB sample data, so let's add a rule that entries must have a cleaning_fee field. Now we can enter a JSON Schema validation document. Support for $jsonSchema is new in Compass 1.18 and we do want to use it so we'll let autocomplete do its thing. The editor is smart enough to know that this early in the rules document, $jsonSchema is a likely candidate to be what we want. As the rules document is currently invalid, there's also nothing displayed in either of the sample document panels. If we go into the editor and start typing, we'll also see some more of the features of the new Validation view:Īs soon as we start typing, we are informed of errors in the rules and autocompletion kicks in offering up possible options. As we update the rule in the editor, the two document windows will also update to give rapid feedback on the effect the rules will have when applied. One will display a document from the collection that passes our validation rule, the other will display a document that fails. Below the editor is a new element, two windows for sample documents. The display is now centered on a JSON editor, with controls for how the validation rules are to be handled above it. We've already logged in and connected with Compass and we're viewing one of the sample datasets available on MongoDB Atlas. You can read about this older experience in " Adding Document Validation Rules Using MongoDB Compass 1.5".įor Compass 1.18, the addition of a context-sensitive, field-aware editor has allowed for the removal of the rules builder to produce a more interactive and responsive validation creation environment. A JSON editor was available to edit the generated rules. In earlier versions of Compass, a rules builder allowed MongoDB's own validation rules to be assembled in a controlled fashion. JSON Schema validation - Dependencies you can depend onįor now, we will continue looking at what's changed in Compass.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |