Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-973

Possible bug in how the new shell handles new $tsIncrement and $tsSecond operators

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.0.4
    • Affects Version/s: None
    • Component/s: Embedded Shell
    • None
    • Not Needed

      It appears that the new MongoDB shell outputs the reverse of what the old shell outputs when using $tsSecond and $tsIncrement operators.

      In the old shell:

      db.stockSales.drop()
      MongoDB Enterprise mongos> db.stockSales.insertMany( [
      ...       { _id: 0, symbol: "ABC", saleTimestamp: Timestamp(1622731060, 1) },
      ...       { _id: 1, symbol: "DEF", saleTimestamp: Timestamp(1714124193, 1) }
      ...    ] )
      { "acknowledged" : true, "insertedIds" : [ 0, 1 ] }
      MongoDB Enterprise mongos> 
      MongoDB Enterprise mongos> db.stockSales.aggregate( [
      ...       {
      ...          $project:
      ...          {
      ...             _id: 0, saleTimestamp: 1, saleIncrement: { $tsIncrement: "$saleTimestamp" }
      ...          }
      ...       }
      ...    ] )
      { "saleTimestamp" : Timestamp(1622731060, 1), "saleIncrement" : NumberLong(1) }
      { "saleTimestamp" : Timestamp(1714124193, 1), "saleIncrement" : NumberLong(1) }
      MongoDB Enterprise mongos> db.stockSales.aggregate( [
      ...       {
      ...          $project:
      ...          {
      ...             _id: 0, saleTimestamp: 1, saleSeconds: { $tsSecond: "$saleTimestamp" }
      ...          }
      ...       }
      ...    ] )
      { "saleTimestamp" : Timestamp(1622731060, 1), "saleSeconds" : NumberLong(1622731060) }
      { "saleTimestamp" : Timestamp(1714124193, 1), "saleSeconds" : NumberLong(1714124193) }
      

      In the new shell:

      Enterprise [direct: mongos] test> db.stockSales.drop()
      true
      Enterprise [direct: mongos] test> db.stockSales.insertMany([ { _id: 0, symbol: "ABC", saleTimestamp: Timestamp(1622731060, 1) }, { _id: 1, symbol: "DEF", saleTimestamp: Timestamp(1714124193, 1) }])
      { acknowledged: true, insertedIds: { '0': 0, '1': 1 } }
      Enterprise [direct: mongos] test> db.stockSales.aggregate( [
      ...       {
      .....          $project:
      .....          {
      .......             _id: 0, saleTimestamp: 1, saleIncrement: { $tsIncrement: "$saleTimestamp" }
      .......          }
      .....       }
      ...    ] )
      [
        {
          saleTimestamp: Timestamp(1622731060, 1),
          saleIncrement: Long("1622731060")
        },
        {
          saleTimestamp: Timestamp(1714124193, 1),
          saleIncrement: Long("1714124193")
        }
      ]
      Enterprise [direct: mongos] test> db.stockSales.aggregate( [
      ...       {
      .....          $project:
      .....          {
      .......             _id: 0, saleTimestamp: 1, saleSeconds: { $tsSecond: "$saleTimestamp" }
      .......          }
      .....       }
      ...    ] )
      [
        { saleTimestamp: Timestamp(1622731060, 1), saleSeconds: Long("1") },
        { saleTimestamp: Timestamp(1714124193, 1), saleSeconds: Long("1") }
      ]
      

      Notice the output from the operators is reversed. The old shell outputs the correct results.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jason.price@mongodb.com Jason Price
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: