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

TimeSeries: inserting a document with a duplicate field breaks the collection

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Triage
    • ALL
    • Hide
      use test17;
      db.createCollection(
          "weather",
          {
             timeseries: {
                timeField: "timestamp",
                metaField: "metadata",
                granularity: "seconds"
             },
             expireAfterSeconds: 86400
          }
       );
      db.weather.insertMany( [
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-18T00:00:00.000Z"),
             temp: 12
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-18T04:00:00.000Z"),
             temp: 11
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-18T08:00:00.000Z"),
             temp: 11
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-18T12:00:00.000Z"),
             temp: 12
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-18T16:00:00.000Z"),
             timestamp: ISODate("2021-05-18T16:00:00.000Z"),
             temp: 16
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-18T20:00:00.000Z"),
             temp: 15
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-19T00:00:00.000Z"),
             temp: 13
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-19T04:00:00.000Z"),
             temp: 12
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-19T08:00:00.000Z"),
             temp: 11
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-19T12:00:00.000Z"),
             temp: 12
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-19T16:00:00.000Z"),
             temp: 17
          },
          {
             metadata: { sensorId: 5578, type: "temperature" },
             timestamp: ISODate("2021-05-19T20:00:00.000Z"),
             temp: 12
          }
       ] );
      db.weather.find({temp:12}); // this will return 5 matching documents
      db.weather.countDocuments(); // this will return 12
      
      db.weather.insert( { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate("2021-05-19T20:00:00.000Z"), temp: 12, temp: 12 })
      
      db.weather.find({temp:12}); // this will now return 1 or 0 matches
      
      db.weather.countDocuments(); // this will now return 0
      
      Show
      use test17; db.createCollection( "weather" , { timeseries: { timeField: "timestamp" , metaField: "metadata" , granularity: "seconds" }, expireAfterSeconds: 86400 } ); db.weather.insertMany( [ { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-18T00:00:00.000Z" ), temp: 12 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-18T04:00:00.000Z" ), temp: 11 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-18T08:00:00.000Z" ), temp: 11 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-18T12:00:00.000Z" ), temp: 12 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-18T16:00:00.000Z" ), timestamp: ISODate( "2021-05-18T16:00:00.000Z" ), temp: 16 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-18T20:00:00.000Z" ), temp: 15 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-19T00:00:00.000Z" ), temp: 13 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-19T04:00:00.000Z" ), temp: 12 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-19T08:00:00.000Z" ), temp: 11 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-19T12:00:00.000Z" ), temp: 12 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-19T16:00:00.000Z" ), temp: 17 }, { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-19T20:00:00.000Z" ), temp: 12 } ] ); db.weather.find({temp:12}); // this will return 5 matching documents db.weather.countDocuments(); // this will return 12 db.weather.insert( { metadata: { sensorId: 5578, type: "temperature" }, timestamp: ISODate( "2021-05-19T20:00:00.000Z" ), temp: 12, temp: 12 }) db.weather.find({temp:12}); // this will now return 1 or 0 matches db.weather.countDocuments(); // this will now return 0

      As per the description, if for an existing timeseries collection a document is inserted that contains duplicate fields, for example:

      db.weather.insert(
       {
          metadata: { sensorId: 5578, type: "temperature" },
          timestamp: ISODate("2021-05-19T20:00:00.000Z"),
          timestamp: ISODate("2021-05-19T20:00:00.000Z"),
          temp: 12
       })
       
       db.weather.insert(
        {
           metadata: { sensorId: 5578, type: "temperature" },
           timestamp: ISODate("2021-05-19T20:00:00.000Z"),
           temp: 12,
           temp: 12
        })
      

      Then, the collection stops returning correct results.

      Reproduced on v8.0.1

            Assignee:
            Unassigned Unassigned
            Reporter:
            dmitry.ryabtsev@mongodb.com Dmitry Ryabtsev
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: