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

Importing document with duplicate definitions can bring db into inconsistent state

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 8.0.1
    • Component/s: None
    • None
    • Storage Execution
    • ALL
    • Hide
      estan@newton:~$ docker run -p 27017:27017 -d mongo:8.0.1
      Unable to find image 'mongo:8.0.1' locally
      8.0.1: Pulling from library/mongo
      Digest: sha256:9342a9279a9841fc5f8192e49dcaaf9404e6bb3a90e8cf134eb96074830dd448
      Status: Downloaded newer image for mongo:8.0.1
      f72d88d2cadb2fe59f8da17c981ea70b075fbba482ccd544ce38606c67f553b7
      estan@newton:~$ echo '[{"_id":{"$oid":"63401fc4859babfd692de2da"},"a":{"b":"a"},"a":{}}]' | mongoimport -h localhost -d testdb -c testcol --jsonArray
      2024-10-18T14:13:30.002+0200    connected to: mongodb://localhost/
      2024-10-18T14:13:30.051+0200    1 document(s) imported successfully. 0 document(s) failed to import.
      estan@newton:~$ mongosh localhost/testdb --eval 'db.getCollection("testcol").find({"a.b":{$exists:true}})'
      [ { _id: ObjectId('63401fc4859babfd692de2da'), a: {} } ]
      estan@newton:~$
      

      As seen above, I queried for documents where a.b exists and got a result, but no b key is exists under a in the returned document.

      Versions used above:

      • MongoDB 8.0.1
      • mongosh 2.3.1
      • mongoimport 100.10.0
      Show
      estan@newton:~$ docker run -p 27017:27017 -d mongo:8.0.1 Unable to find image 'mongo:8.0.1' locally 8.0.1: Pulling from library/mongo Digest: sha256:9342a9279a9841fc5f8192e49dcaaf9404e6bb3a90e8cf134eb96074830dd448 Status: Downloaded newer image for mongo:8.0.1 f72d88d2cadb2fe59f8da17c981ea70b075fbba482ccd544ce38606c67f553b7 estan@newton:~$ echo '[{"_id":{"$oid":"63401fc4859babfd692de2da"},"a":{"b":"a"},"a":{}}]' | mongoimport -h localhost -d testdb -c testcol --jsonArray 2024-10-18T14:13:30.002+0200 connected to: mongodb://localhost/ 2024-10-18T14:13:30.051+0200 1 document(s) imported successfully. 0 document(s) failed to import. estan@newton:~$ mongosh localhost/testdb --eval 'db.getCollection("testcol").find({"a.b":{$exists:true}})' [ { _id: ObjectId('63401fc4859babfd692de2da'), a: {} } ] estan@newton:~$ As seen above, I queried for documents where a.b exists and got a result, but no b key is exists under a in the returned document. Versions used above: MongoDB 8.0.1 mongosh 2.3.1 mongoimport 100.10.0

      MongoDB server silently accepts importing of malformed documents like {{

      {"_id":\{"$oid":"63401fc4859babfd692de2da"}

      ,"a":{"b":"a"},"a":{}}}} which has a duplicate definition of a.b.

      After importing such a document, the database is in an inconsistent state in which queries can behave in unexpected ways. For example, after import of this document, if you query for documents that have a.b, the document will show up in the result, but the returned document does not have that key.

      MongoDB should reject import of such documents.

            Assignee:
            Unassigned Unassigned
            Reporter:
            elvstone@gmail.com Elvis Stansvik
            Votes:
            0 Vote for this issue
            Watchers:
            10 Start watching this issue

              Created:
              Updated:
              Resolved: