【发布时间】:2021-04-25 01:41:30
【问题描述】:
我们有一个 MongoDB 副本并读取到 scondaries,在后端我们使用带有 feathers-mongoose 的feathersjs,并且 Document 有一个 SubDocument。在打了补丁后,我们取回了旧的子文档。我们已经设置了new: true,也尝试了returnNewDocument: true
const params = {
mongoose: {
new: true
}
}
查看 feathers-mongoose 的文档告诉我,参数中的 mongoose 应该作为 mongoose 的选项:https://github.com/feathersjs-ecosystem/feathers-mongoose#paramsmongoose
但是 SubDocument 仍然有旧的 id。 SubDocuments 有什么特别的事情要做吗?
我也对 mongoose 和 mongodb 的文档感到困惑,因为 mongoDB seam 只知道 returnNewDocument 和 mongoose 只知道 new?
MongoDB:https://docs.mongodb.com/v4.2/reference/method/db.collection.findOneAndUpdate/
猫鼬:https://mongoosejs.com/docs/migration.html#findandmodify-new
架构如下:
const timeSchema = new Schema({
weekday: {
type: Number,
min: 0,
max: 6,
required: true,
},
startTime: { type: Number },
duration: { type: Number },
eventId: { type: String },
room: { type: String },
});
const courseSchema = getUserGroupSchema({
description: { type: String },
startDate: { type: Date },
untilDate: { type: Date },
shareToken: {
type: String,
unique: true,
sparse: true,
},
// here is the reference
times: [timeSchema],
// optional information if this course is a copy from other
isCopyFrom: { type: Schema.Types.ObjectId, default: null },
features: [{ type: String, enum: Object.values(COURSE_FEATURES) }],
...externalSourceSchema,
});
【问题讨论】:
标签: node.js mongodb mongoose feathersjs mongodb-replica-set