$elemMatch does not work after creating an index on the nested array!

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Critical - P2
    • None
    • Affects Version/s: 3.0.0
    • Component/s: None
    • Environment:
      Windows 10, x64
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      I have a database with a collection 'institutions'. It has a field with an array of tuples: 'institutions.person_id_role_id'. Each tuple is a pair of ObjectIds pointing to the collection 'person' and 'role', respectively.

      The following expression works well:
      db.getCollection('institutions').find({ "person_id_role_id" : { "$elemMatch" : { "0" : {$eq:ObjectId("59bec3d719f9d536a018438e")}}}});

      After I index parts of the array of pairs:
      db.getCollection('institutions').ensureIndex(

      {"person_id_role_id.0":1}

      );
      db.getCollection('institutions').ensureIndex(

      {"person_id_role_id.1":1}

      );

      ... the upper expression does not work anymore. If I delete the index, it works again.

      I feel as if something is wrong here. Perhaps the indexing does not resolve ".0" correctly (sometimes meaning first array pair, and sometimes meaning left part of the pair in the array).

      Please help! How would you solve this?

            Assignee:
            Unassigned
            Reporter:
            Artur
            None
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: