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

Using $densify with partition on the nested field produces extra document and a flat partition field

    • Fully Compatible
    • ALL
    • v5.1
    • QO 2021-11-29

      db.getSiblingDB("test").weather.insertMany( [
         {
             "_id": 0,
             "metadata": { "sensorId": 5578, "type": "temperature" },
             "timestamp": ISODate("2021-05-18T00:00:00.000Z"),
             "temp": 12
         },
         {"_id": 1,
             "metadata": { "sensorId": 5578, "type": "temperature" },
             "timestamp": ISODate("2021-05-18T02:00:00.000Z"),
             "temp": 14
         }
      ] );
      
      db.getSiblingDB("test").weather.aggregate([
          {
                  $densify: {
                      field: "timestamp",
                      partitionByFields: ["metadata.sensorId"],
                      range: {
                           step: 1,
                           unit: "hour",
                           bounds: "full"
                      }
                  }
              }
          ]);
      

      Output:
      1) It was supposed to create just one new document, but there's an extra document in the end without partition filed.
      2) In the created document partition field metadata: {sensorId: 5578} became "metadata.sensorId": 5578

      [
        {
          "_id": 0,
          "metadata": {
            "sensorId": 5578,
            "type": "temperature"
          },
          "timestamp": {
            "$date": "2021-05-18T00:00:00Z"
          },
          "temp": 12
        },
        {
          "metadata.sensorId": 5578,
          "timestamp": {
            "$date": "2021-05-18T01:00:00Z"
          }
        },
        {
          "_id": 1,
          "metadata": {
            "sensorId": 5578,
            "type": "temperature"
          },
          "timestamp": {
            "$date": "2021-05-18T02:00:00Z"
          },
          "temp": 14
        },
        {
          "timestamp": {
            "$date": "2021-05-18T02:00:00Z"
          }
        }
      ]
      

      Expected output:

      [
        {
          "_id": 0,
          "metadata": {
            "sensorId": 5578,
            "type": "temperature"
          },
          "timestamp": {
            "$date": "2021-05-18T00:00:00Z"
          },
          "temp": 12
        },
        {
          "metadata": {
            "sensorId": 5578
          },
          "timestamp": {
            "$date": "2021-05-18T01:00:00Z"
          }
        },
        {
          "_id": 1,
          "metadata": {
            "sensorId": 5578,
            "type": "temperature"
          },
          "timestamp": {
            "$date": "2021-05-18T02:00:00Z"
          },
          "temp": 14
        }
      ]
      

            Assignee:
            david.percy@mongodb.com David Percy
            Reporter:
            kateryna.kamenieva@mongodb.com Katya Kamenieva
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: