【发布时间】:2023-01-29 21:20:23
【问题描述】:
我正在使用今天最新的猫鼬版本 (6.2.7),我遇到了一个非常奇怪的错误。
这是我的架构:
const testSchema = new Schema<ITestSchema>({
age: Number
}, { timestamps: true });
const testModel = model<ITestSchema>("test", testSchema);
当我用它创建新系列时,一切都很完美!并且我将时间戳(updatedAt 和 createdAt)添加到集合中。
但当我处理会话时,不会添加时间戳,我只看到“age”、“_d”和“__v”。
这是使用会话创建的示例代码:
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();
}
};
我尝试多次阅读文档并在线搜索类似问题但找不到任何问题。
谢谢 3>
【问题讨论】: