【发布时间】:2018-11-29 06:52:10
【问题描述】:
这是我的带有watched 和watchLater 数组的用户模型:
const UserSchema = new mongoose.Schema(
{
email: { type: String, required: true, unique: true },
watched: [{ type: Number }],
watchLater: [{ type: Number }],
},
{ timestamps: true },
)
我有这个功能,我想从watchLater 中删除 id 并添加到watched:
async addToWatched(id) {
const _id = this.getUserId()
return await this.store.User.findByIdAndUpdate(
{ _id },
// remove id from watchLater and add to watched,
{ new: true },
)
}
我该怎么做?
【问题讨论】: