'When working with sessions, timestamps are not added

I'm working with the latest mongoose version of today (6.2.7) and I'm having a really weird bug.

This is my Schema:

const testSchema = new Schema<ITestSchema>({
  age: Number
}, { timestamps: true });

const testModel = model<ITestSchema>("test", testSchema);

When I'm creating new collections out of it everything is working perfect! and I'm getting timestamps (updatedAt and createdAt) added to the collection.

But When I'm working with sessions the timestamps are not added and i see only "age", "_d" and "__v".

This is the example code for the creation with the sessions:

const test = async () => {
    const session: ClientSession = await mongoose.startSession();

    try {
        session.startTransaction();

        const newTest = new testModel({
            age: 30,
        }, { session });

        await newTest.save({ session });

        await session.commitTransaction();
    } catch (error) {
        await session.abortTransaction();
        throw error;
    } finally {
        await session.endSession();
    }
};

I tried read the doc several times and searched for similar issues online but could not find any.

Thanks 3>



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source