[SERVER-61548] Using $densify with partition on the nested field produces extra document and a flat partition field Created: 16/Nov/21  Updated: 29/Oct/23  Resolved: 22/Nov/21

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: 5.2.0, 5.1.2

Type: Bug Priority: Major - P3
Reporter: Katya Kamenieva Assignee: David Percy
Resolution: Fixed Votes: 0
Labels: query-director-triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Screen Shot 2021-11-16 at 15.24.52.png    
Issue Links:
Backports
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v5.1
Sprint: QO 2021-11-29
Participants:

 Description   

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
  }
]



 Comments   
Comment by Githook User [ 24/Nov/21 ]

Author:

{'name': 'David Percy', 'email': 'david.percy@mongodb.com', 'username': 'dpercy'}

Message: SERVER-61548 Handle dotted partitionByFields in $densify
Branch: v5.1
https://github.com/mongodb/mongo/commit/c385e756e42efebfcdbba66a56e7536067b4b35e

Comment by Githook User [ 22/Nov/21 ]

Author:

{'name': 'David Percy', 'email': 'david.percy@mongodb.com', 'username': 'dpercy'}

Message: SERVER-61548 Handle dotted partitionByFields in $densify
Branch: master
https://github.com/mongodb/mongo/commit/a39a201c7c6991132494187f25e34151db1ef5c7

Generated at Thu Feb 08 05:52:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.