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

indexes causing non-distinct results in $or query

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: 1.6.3, 1.6.4, 1.6.5
    • None
    • Environment:
      OSX, CentOS, Linux, 32 and 64 bit
    • ALL

      I'm not sure how to describe this. So I made a gist.

      https://gist.github.com/743921

      If I run the query in question with only one object in the collection I get back two copies of the object.

      Indexes
      ======
      > db.system.indexes.find()
      { "name" : "id", "ns" : "t1d_development.users", "key" :

      { "_id" : 1 }

      }
      { "name" : "email_1_encrypted_password_1", "ns" : "t1d_development.users", "key" :

      { "email" : 1, "encrypted_password" : 1 }

      , "unique" : true }
      { "name" : "memberships_1", "ns" : "t1d_development.users", "key" :

      { "memberships" : 1 }

      , "unique" : false }
      { "name" : "acl_fields.public_1", "ns" : "t1d_development.users", "key" :

      { "acl_fields.public" : 1 }

      , "unique" : false }
      { "name" : "acl_fields.value_1", "ns" : "t1d_development.users", "key" :

      { "acl_fields.value" : 1 }

      , "unique" : false }
      { "name" : "acl_fields.circles_1", "ns" : "t1d_development.users", "key" :

      { "acl_fields.circles" : 1 }

      , "unique" : false }

      Object
      =====
      db.users.findOne()
      {
      "_id" : ObjectId("4d0a54246a931656bc000006"),
      "acl_fields" : [

      { "circles" : [ ], "name" : "first_name", "public" : false, "value" : "Amos", "_id" : ObjectId("4d0a54246a931656bc000005"), "_type" : "AccessControlledFields::AclFirstName" }

      ,

      { "circles" : [ ], "name" : "email", "public" : false, "value" : "amos@amos.com", "_id" : ObjectId("4d0a54246a931656bc000007"), "_type" : "AccessControlledFields::AclEmail" }

      ,

      { "circles" : [ ], "name" : "nickname", "public" : true, "value" : "aking", "_id" : ObjectId("4d0a54686a931656bc000009"), "_type" : "AccessControlledFields::AclNickname" }

      ,

      { "circles" : [ ], "name" : "race_ethnicity", "public" : false, "value" : [ ], "_id" : ObjectId("4d0a62316a931656bc00000a"), "_type" : "AccessControlledFields::AclRaceEthnicity" }

      ,

      { "circles" : [ ], "name" : "middle_name", "public" : false, "value" : "", "_id" : ObjectId("4d0a62316a931656bc00000b"), "_type" : "AccessControlledFields::AclMiddleName" }

      ,

      { "circles" : [ ], "name" : "last_name", "public" : false, "value" : "", "_id" : ObjectId("4d0a62316a931656bc00000c"), "_type" : "AccessControlledFields::AclLastName" }

      ,

      { "circles" : [ ], "name" : "gender", "public" : false, "value" : "Male", "_id" : ObjectId("4d0a62316a931656bc00000d"), "_type" : "AccessControlledFields::AclGender" }

      ,

      { "circles" : [ ], "name" : "zip_code", "public" : false, "value" : "", "_id" : ObjectId("4d0a62316a931656bc00000e"), "_type" : "AccessControlledFields::AclZipCode" }

      ,

      { "circles" : [ ], "name" : "date_of_birth", "public" : false, "value" : null, "_id" : ObjectId("4d0a62316a931656bc00000f"), "_type" : "AccessControlledFields::AclDateOfBirth" }

      ],
      "confirmation_sent_at" : "Thu Dec 16 2010 12:02:12 GMT-0600 (CST)",
      "confirmation_token" : null,
      "confirmed_at" : "Thu Dec 16 2010 12:03:20 GMT-0600 (CST)",
      "connections_circle_of_trust" :

      { "name" : "Connections", "email" : false, "date_of_birth" : false, "race_ethnicity" : false, "gender" : false, "first_name" : false, "middle_name" : false, "last_name" : false, "zip_code" : false, "_id" : ObjectId("4d0a54246a931656bc000008") }

      ,
      "created_at" : "Thu Dec 16 2010 12:02:12 GMT-0600 (CST)",
      "current_sign_in_at" : "Thu Dec 16 2010 12:03:20 GMT-0600 (CST)",
      "current_sign_in_ip" : "127.0.0.1",
      "email" : "amos@amos.com",
      "encrypted_password" : "$2a$10$/dgVQhHdIYjSJa6yz6RWbezcuVjzwT1rj70PpybwjzN56i8X8.aBu",
      "first_name" : "Amos",
      "gender" : "Male",
      "last_name" : "",
      "last_sign_in_at" : "Thu Dec 16 2010 12:03:20 GMT-0600 (CST)",
      "last_sign_in_ip" : "127.0.0.1",
      "memberships" : [ ],
      "middle_name" : "",
      "nickname" : "aking",
      "password_salt" : "$2a$10$/dgVQhHdIYjSJa6yz6RWbe",
      "race_ethnicity" : [ ],
      "sign_in_count" : 1,
      "terms_acceptance" : "1",
      "updated_at" : "Thu Dec 16 2010 13:02:09 GMT-0600 (CST)",
      "zip_code" : ""
      }

      Query
      =====
      db.users.find({$or:[
      {acl_fields:{$elemMatch:{name:{$ne:"gender"}, circles:{$in:[]}, value : /aking/i}}},
      {acl_fields:{$elemMatch:{name:"gender", circles:{$in:[]}, value : /^aking$/i}}},
      {acl_fields:{$elemMatch:

      {name:"gender", public:true, value : /^aking$/i}

      }},
      {acl_fields:{$elemMatch:{name:{$ne:"gender"}, public:true, value:/aking/i}}}]})

            Assignee:
            aaron Aaron Staple
            Reporter:
            adkron Amos King
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: