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

Query does not return a document when the sub-document fields are not listed in the same order as they exist in the document

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.2.16
    • Component/s: Querying
    • None
    • ALL
    • Hide

      As provided in description. I have tested this in MongoDB 3.2

      Show
      As provided in description. I have tested this in MongoDB 3.2

      Assume the collection name "groups"

      Sample Document:

      {
          "_id" : ObjectId("597620fcba76f211586c9203"),
          "task" : {
              "taskId" : ObjectId("597620fcba76f211586c9402"),
              "hasTasks" : true
          }
      }
      

      Failing Query:

      db.getCollection('groups').find({task: { hasTasks: true, taskId: ObjectId("597620fcba76f211586c9402")}, _id: ObjectId("597620fcba76f211586c9203") })
      
      

      Passing Query:

      db.getCollection('groups').find({task: { taskId: ObjectId("597620fcba76f211586c9402"), hasTasks: true, }, _id: ObjectId("597620fcba76f211586c9203") })
      
      

      As you can see, if the order of the query fields in the sub-document (viz. task) does not match the order in which it exists in the document, query does not return any results.

            Assignee:
            mark.agarunov Mark Agarunov
            Reporter:
            catchshyam Shyam Prakash RK
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: