-
Creating a collection now supports options to enable validation of a JSON schema that documents must adhere to before they are permitted to be inserted or updated. The
ModifyCollection()method added in this release allows updating the schema of an existing collection. In addition, thecreateCollection()method's option for reusing an existing collection has been renamed fromReuseExistingObjecttoreuseExisting.Schema validation is performed by the server, which returns an error message if a document in a collection does not match the schema definition or if the server does not support validation.
If a given collection already exists in the database,
createCollection()fails unlessreuseExistingis enabled in an additional options object, as shown in the following example:const mysqlx = require('@mysql/xdevapi'); mysqlx.getSession('mysqlx://localhost:33060') .then(sesion => { return session.getSchema('mySchema').createCollection('myCollection', { reuseExisting: true }) });You can also use the options object, for example, to create a serverside document validation schema. To do this, include a schema property matching a valid JSON schema definition within an outer validation object. You should also include the
levelproperty whereSTRICTenables validation andOFFdisables it, as shown in the following example:const mysqlx = require('@mysql/xdevapi'); const validation = { schema: { type: 'object', properties: { name: { type: 'string' } } }, level: mysqlx.Schema.ValidationLevel.STRICT }; mysqlx.getSession('mysqlx://localhost:33060') .then(sesion => { return session.getSchema('mySchema').createCollection('myCollection', { validation }) });The same
levelproperty logic applies tomodifyCollection(). This example shows how to enable a JSON schema on an existing collection (or to update it, if it already exists) using theSTRICTvalidation level:const mysqlx = require('@mysql/xdevapi'); const validation = { schema: { type: 'object', properties: { name: { type: 'string' } } }, level: mysqlx.Schema.ValidationLevel.STRICT }; mysqlx.getSession('mysqlx://localhost:33060') .then(sesion => { return session.getSchema('mySchema').modifyCollection('myCollection', { validation }) });(WL #13333)
Row values for columns of type
BIGINTwere not correctly decoded by Connector/Node.js. We fix this problem by upgrading the includedgoogle-protobuflibrary to version 3.11.4. (Bug #27570685)