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

Why sub document cannot match index?

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Index Maintenance
    • None
    • Environment:
      WINDOWS2008 R2
    • ALL
    • Hide
      /* sample collection items */
      {
          "_id" : ObjectId("56e1b0520ba71ca0485a386a"),
          "uid" : 9843,
          "sub" : {
              "date" : ISODate("2016-03-09T22:54:09.549+08:00"),
              "status" : "PLACE_ORDER_SUCCESS",
              "arr" : {
                  "taskids" : [],
                  "ids" : [ 
                      "56c56639ef68fc0e28524aab", 
                      "56c5663aef68fc0e28524ab6", 
                      "56c5663aef68fc0e28524ab7", 
                      "56c5663aef68fc0e28524ab8", 
                      "56c5663aef68fc0e28524ab9"
                  ]
              }
          }
      }
      
      /* sample index */
      {
          "uid" : -1,
          "sub.status" : 1,
          "sub.arr.ids" : 1,
          "sub.date" : 1
      }
      
      
      
      /* sample search explain */
      db.getCollection('sample').find({    "uid" : 9843,
          "sub.date" :  new Date(1456239231000),
          "sub.status" : "PLACE_ORDER_SUCCESS",
          "sub.arr.ids" : "56c56639ef68fc0e28524aab"
      
          }).explain()
      
      
      
      /* sample index have 2 miss */
      {
          "uid" : [ 
              "[9843.0, 9843.0]"
          ],
          "sub.status" : [ 
              "[MinKey, MaxKey]"
          ],
          "sub.arr.ids" : [ 
              "[\"56c56639ef68fc0e28524aab\", \"56c56639ef68fc0e28524aab\"]"
          ],
          "sub.date" : [ 
              "[MinKey, MaxKey]"
          ]
      }
      
      /* sample_root collection items */
      
      {
          "_id" : ObjectId("56e1b0520ba71ca0485a386a"),
          "uid" : 9843,
          "date" : ISODate("2016-03-09T22:54:09.549+08:00"),
          "status" : "PLACE_ORDER_SUCCESS",
          "arr" : {
              "taskids" : [],
              "ids" : [ 
                  "56c56639ef68fc0e28524aab", 
                  "56c5663aef68fc0e28524ab6", 
                  "56c5663aef68fc0e28524ab7", 
                  "56c5663aef68fc0e28524ab8", 
                  "56c5663aef68fc0e28524ab9"
              ]
          }
      }
      
      
      
      
      /* sample_root index */
      
      {
          "uid" : -1,
          "status" : 1,
          "arr.ids" : 1,
          "date" : 1
      }
      
      
      
      /* sample_root search explain */
      db.getCollection('sample_root').find({    "uid" : 9843,
          "date" :  new Date(1456239231000),
          "status" : "PLACE_ORDER_SUCCESS",
          "arr.ids" : "56c56639ef68fc0e28524aab"
      
          }).explain()
      
      
      /* sample_root match all */
      {
          "uid" : [ 
              "[9843.0, 9843.0]"
          ],
          "status" : [ 
              "[\"PLACE_ORDER_SUCCESS\", \"PLACE_ORDER_SUCCESS\"]"
          ],
          "arr.ids" : [ 
              "[\"56c56639ef68fc0e28524aab\", \"56c56639ef68fc0e28524aab\"]"
          ],
          "date" : [ 
              "[new Date(1456239231000), new Date(1456239231000)]"
          ]
      }
      
      Show
      /* sample collection items */ { "_id" : ObjectId("56e1b0520ba71ca0485a386a"), "uid" : 9843, "sub" : { "date" : ISODate("2016-03-09T22:54:09.549+08:00"), "status" : "PLACE_ORDER_SUCCESS", "arr" : { "taskids" : [], "ids" : [ "56c56639ef68fc0e28524aab", "56c5663aef68fc0e28524ab6", "56c5663aef68fc0e28524ab7", "56c5663aef68fc0e28524ab8", "56c5663aef68fc0e28524ab9" ] } } } /* sample index */ { "uid" : -1, "sub.status" : 1, "sub.arr.ids" : 1, "sub.date" : 1 } /* sample search explain */ db.getCollection('sample').find({ "uid" : 9843, "sub.date" : new Date(1456239231000), "sub.status" : "PLACE_ORDER_SUCCESS", "sub.arr.ids" : "56c56639ef68fc0e28524aab" }).explain() /* sample index have 2 miss */ { "uid" : [ "[9843.0, 9843.0]" ], "sub.status" : [ "[MinKey, MaxKey]" ], "sub.arr.ids" : [ "[\"56c56639ef68fc0e28524aab\", \"56c56639ef68fc0e28524aab\"]" ], "sub.date" : [ "[MinKey, MaxKey]" ] } /* sample_root collection items */ { "_id" : ObjectId("56e1b0520ba71ca0485a386a"), "uid" : 9843, "date" : ISODate("2016-03-09T22:54:09.549+08:00"), "status" : "PLACE_ORDER_SUCCESS", "arr" : { "taskids" : [], "ids" : [ "56c56639ef68fc0e28524aab", "56c5663aef68fc0e28524ab6", "56c5663aef68fc0e28524ab7", "56c5663aef68fc0e28524ab8", "56c5663aef68fc0e28524ab9" ] } } /* sample_root index */ { "uid" : -1, "status" : 1, "arr.ids" : 1, "date" : 1 } /* sample_root search explain */ db.getCollection('sample_root').find({ "uid" : 9843, "date" : new Date(1456239231000), "status" : "PLACE_ORDER_SUCCESS", "arr.ids" : "56c56639ef68fc0e28524aab" }).explain() /* sample_root match all */ { "uid" : [ "[9843.0, 9843.0]" ], "status" : [ "[\"PLACE_ORDER_SUCCESS\", \"PLACE_ORDER_SUCCESS\"]" ], "arr.ids" : [ "[\"56c56639ef68fc0e28524aab\", \"56c56639ef68fc0e28524aab\"]" ], "date" : [ "[new Date(1456239231000), new Date(1456239231000)]" ] }

      I create one test collection named sample and sample_root.
      sample_root all property is in root. and sample some property inside at sub document.
      They are create same index.
      so, when I search and explain it, I saw that index match are difference.
      so what happend?

      how can I match sub document index?

      attach all code in here:

            Assignee:
            kelsey.schubert@mongodb.com Kelsey Schubert
            Reporter:
            tianwei02 raylynn
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: