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

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

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

      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 Unassigned
            Reporter:
            wanderer Artur
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: