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

Resultset change with 2x $or clauses at same level

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.6.12
    • Component/s: None
    • Labels:
      None
    • ALL
    • Hide

      Below the insert Script
       
      This query returns two documents
       
      db.getCollection('test').find({
         
      'status': 'current'
       
      ,$or: [
      {'identifier':  {$elemMatch:

      {'system': 'urn:ihe:iti:xds:2013:accession', 'value': '1'}

      }}
      ],
       
       $or: [
      {'patientId.value':  {$in: [
      '693561'
       
      ]}}
      ]
       
      , 'type.coding.code': 'master'
      })
       
      Whereas 
      this query returns only one document
       
      db.getCollection('test').find({
          $or: [
      {'patientId.value':  {$in: [
      '693561'
       
      ]}}
      ],
      'status': 'current'
       
      ,$or: [
      {'identifier':  {$elemMatch:

      {'system': 'urn:ihe:iti:xds:2013:accession', 'value': '1'}

      }}
      ]
      , 'type.coding.code': 'master'
      })
       
      Where is my mistake ?
       
       
      Thanks a lot
       
       
      *INSERT SCRIPT:
      *
       
      db.getCollection('test').insert({
          "status" : "current",
              "identifier" : [
                 

      {                 "use" : "temp",                 "system" : "[http://www.bmc.nl/zorgportal/identifiers/encounters]",                 "value" : "Encounter_Roel_20130404"             }

              ],
              "type" : [
                  {
                      "coding" : [
                         

      {                         "system" : "[http://snomed.info/sct]",                         "code" : "11429006",                         "display" : "Master 123A"                     }

      ,
                         

      {                         "system" : "[http://hl7.org/fhir/encounter-type]",                         "code" : "master",                         "display" : "master"                     }

                      ]
                  }
              ],
             
          "patientId" :

      {         "value" : "693561"     }

      }
      );
      db.getCollection('test').insert({
      "status" : "current",
          "patientId" :

      {         "value" : "693561"     }

      ,
              "identifier" : [
                 

      {                 "use" : "temp",                 "system" : "urn:ihe:iti:xds:2013:accession",                 "value" : "1"             }

              ],
              "type" : [
                  {
                      "coding" : [
                         

      {                         "system" : "[http://snomed.info/sct]",                         "code" : "11429006",                         "display" : "Consultation"                     }

      ,
                         

      {                         "system" : "[http://hl7.org/fhir/encounter-type]",                         "code" : "master",                         "display" : "master"                     }

                      ]
                  }
              ]
      }
      );

      Show
      Below the insert Script   This query returns two documents   db.getCollection('test').find({     'status': 'current'   ,$or: [ {'identifier':  {$elemMatch: {'system': 'urn:ihe:iti:xds:2013:accession', 'value': '1'} }} ],    $or: [ {'patientId.value':  {$in: [ '693561'   ]}} ]   , 'type.coding.code': 'master' })   Whereas   this query returns only one document   db.getCollection('test').find({     $or: [ {'patientId.value':  {$in: [ '693561'   ]}} ], 'status': 'current'   ,$or: [ {'identifier':  {$elemMatch: {'system': 'urn:ihe:iti:xds:2013:accession', 'value': '1'} }} ] , 'type.coding.code': 'master' })   Where is my mistake ?     Thanks a lot     *INSERT SCRIPT: *   db.getCollection('test').insert({     "status" : "current",         "identifier" : [             {                 "use" : "temp",                 "system" : "[http://www.bmc.nl/zorgportal/identifiers/encounters]",                 "value" : "Encounter_Roel_20130404"             }         ],         "type" : [             {                 "coding" : [                     {                         "system" : "[http://snomed.info/sct]",                         "code" : "11429006",                         "display" : "Master 123A"                     } ,                     {                         "system" : "[http://hl7.org/fhir/encounter-type]",                         "code" : "master",                         "display" : "master"                     }                 ]             }         ],             "patientId" : {         "value" : "693561"     } } ); db.getCollection('test').insert({ "status" : "current",     "patientId" : {         "value" : "693561"     } ,         "identifier" : [             {                 "use" : "temp",                 "system" : "urn:ihe:iti:xds:2013:accession",                 "value" : "1"             }         ],         "type" : [             {                 "coding" : [                     {                         "system" : "[http://snomed.info/sct]",                         "code" : "11429006",                         "display" : "Consultation"                     } ,                     {                         "system" : "[http://hl7.org/fhir/encounter-type]",                         "code" : "master",                         "display" : "master"                     }                 ]             }         ] } );

      Hi,
         I have a problem with $or clause.
       
      I create  two documents in a test collection. 
      When I search a document with a $or clause at the end of the query, It returns two documents, whereas if I move $or as first clause the query returns only one document
       
       

            Assignee:
            eric.sedor@mongodb.com Eric Sedor
            Reporter:
            abozzetto Andrea Bozzetto
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: