示例代码如下:
var UserSchema = new Schema({
interactions: [{
interactor: {
type: Schema.Types.ObjectId,
ref: 'User'
}
}]
});
我现在想根据userId匹配所有interactor的值为userId的interaction,用mongoose如何能做到呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
匹配的问题我找到了解决办法,非常直观:
可是在回调函数中我会对匹配的多个users做更新,更新完之后应该如何保存呢?没有users.save()这个方法,难道得自己写loop save?