Documentation Home
MySQL Connector/Node.js Release Notes
Download these Release Notes
PDF (US Ltr) - 119.8Kb
PDF (A4) - 119.5Kb


MySQL Connector/Node.js Release Notes  /  Changes in MySQL Connector/Node.js 8.0  /  Changes in MySQL Connector/Node.js 8.0.21 (2020-07-13, General Availability)

Changes in MySQL Connector/Node.js 8.0.21 (2020-07-13, General Availability)

Functionality Added or Changed

  • 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, the createCollection() method's option for reusing an existing collection has been renamed from ReuseExistingObject to reuseExisting.

    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 unless reuseExisting is 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 level property where STRICT enables validation and OFF disables 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 level property logic applies to modifyCollection(). This example shows how to enable a JSON schema on an existing collection (or to update it, if it already exists) using the STRICT validation 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)

Bugs Fixed

  • Row values for columns of type BIGINT were not correctly decoded by Connector/Node.js. We fix this problem by upgrading the included google-protobuf library to version 3.11.4. (Bug #27570685)