Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1409

Inserts with invalid records are permitted by the driver

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.3
    • Affects Version/s: 3.0.6
    • Component/s: js-bson

      Description

      In https://docs.mongodb.com/manual/core/document/ I saw that "The field names cannot contain the dot (.) character." but I have managed to insert broken documents using the default code options of the nodejs 3.0.6 driver.

      Steps to reproduce

      • Install the environment :
        1. mongodb 3.2.18, node v8.11.1, npm 5.6.0, ubuntu 12.04
        2. package.json
        "dependencies": {
            "mongodb": "^3.0.6",
        }
        
      • Run the following index.js file:
        const {MongoClient} = require('mongodb');
        
        const uri = 'mongodb://localhost:27017/admin';
        
        (async () => {
        
            const client = await MongoClient.connect(uri);
            const db = client.db('test');
        
            let records = [{
                "a.b.c": 1
            }, {
                "d.e": 1
            }
            ];
        
            await db.collection("sample").insertMany(records);
        
            let dbRecords = await db.collection("sample").find({}).toArray();
            console.log(dbRecords);
        
        })();
        

      Found results

      [ { _id: 5ad05493f5f7cfd420a2ac44, 'a.b.c': 1 },
        { _id: 5ad05493f5f7cfd420a2ac45, 'd.e': 1 } ]
      

      Expected Results

      An error should be thrown by the driver like in version 2.2.X

      Workaround

      From what I see, the users must explicitly pass the :

      {
         checkKeys:true 
      }
      

      to the options parameter of the insertMany function.

      Notes

            Assignee:
            katherine.walker@mongodb.com Katherine Walker (Inactive)
            Reporter:
            adobre@bitdefender.com Alexandru Dobre
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: