Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-50243

validationAction: warn only logs warnings on mongo server logs

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Declined
    • Icon: Minor - P4 Minor - P4
    • None
    • 4.2.6
    • None
    • None

    Description

      When using JSON schema validation together with `validationAction: warn`, the warning messages are only logged on the mongo server logs.

      The consuming application does not receive any logs through the driver logs. The `validationAction: warn` has no use for consuming apps, if they can't track the validation issues.

      Steps to reproduce:

      const { MongoClient, Logger } = require('mongodb');
       
      (async () => {
        Logger.setLevel('debug');
        Logger.setCurrentLogger(msg => console.log(msg));
       
        const client = await MongoClient.connect('mongodb://127.0.0.1:27017/?replSet=rs0');
        const db = await client.db('testdb');
        await db.command({
          collMod: 'tests',
          validator: {
            $jsonSchema: {
              type: 'object',
              additionalProperties: false,
              properties: {
                score: { type: 'number' }
              }
            }
          },
          validationAction: 'warn'
        });
        await db.collection('tests').insertOne({ bogus: true });
      })();
      

      Mongo server logs:

      W STORAGE [conn10] Document would fail validation collection: testdb.tests doc: { _id: ObjectId('5f324fcbee2baed9ceccfd3a'), bogus: true }

      Attachments

        Activity

          People

            dmitry.agranat@mongodb.com Dmitry Agranat
            avaly@plexapp.com Valentin Agachi
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: