-
Type: Task
-
Resolution: Fixed
-
Priority: Minor - P4
-
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.