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

The existence of index affects the type of projection field.

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.4.10
    • Component/s: Querying
    • None
    • Environment:
      Windows 2012 (64 bit), windows 7 sp1 (64 bit)
    • ALL
    • Hide

      Unzip the appTasks.zip -> appTasks.json
      Import the appTasks.json file:

      mongoimport -h localhost:27017 -u <user> -p <password> --authenticationDatabase <db> -d test -c appTasks --drop --file appTasks.json
      

      Enter the data base with mongo shell.

      run the query:

      db.appTasks.find({ "taskState" : 1, "isFolderLocking" : true, "affectedFolders" : { "$in" : [NumberLong("1000000000000114891")] } },{"affectedFolders":1, "_id":0})
      

      The result is:

      { "affectedFolders" : [ NumberLong("1000000000000114891") ] }
      

      This result is correct because the field 'affectedFolders' is an array of int64.

      create the following index:

      db.appTasks.createIndex({"taskState":1, "isFolderLocking":1, "affectedFolders":1})
      

      run the query again:

      db.appTasks.createIndex({"taskState":1, "isFolderLocking":1, "affectedFolders":1})
      

      The result is:

      { "affectedFolders" : NumberLong("1000000000000114891") }
      

      This result is incorrect because the returned type is int64 instead of an array of int64.

      Show
      Unzip the appTasks.zip -> appTasks.json Import the appTasks.json file: mongoimport -h localhost:27017 -u <user> -p <password> --authenticationDatabase <db> -d test -c appTasks --drop --file appTasks.json Enter the data base with mongo shell. run the query: db.appTasks.find({ "taskState" : 1, "isFolderLocking" : true, "affectedFolders" : { "$in" : [NumberLong("1000000000000114891")] } },{"affectedFolders":1, "_id":0}) The result is: { "affectedFolders" : [ NumberLong("1000000000000114891") ] } This result is correct because the field 'affectedFolders' is an array of int64. create the following index: db.appTasks.createIndex({"taskState":1, "isFolderLocking":1, "affectedFolders":1}) run the query again: db.appTasks.createIndex({"taskState":1, "isFolderLocking":1, "affectedFolders":1}) The result is: { "affectedFolders" : NumberLong("1000000000000114891") } This result is incorrect because the returned type is int64 instead of an array of int64.

      A field that is an array of int64 is projected as int64 if an index that include the field exists.

            Assignee:
            mark.agarunov Mark Agarunov
            Reporter:
            itzikkg Itzhak Kagan
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: