亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

mongodb - 如何根據(jù)嵌套的屬性值查找(第一層屬性值是數(shù)組)?
巴扎黑
巴扎黑 2017-04-24 09:11:50
0
1
739

示例代碼如下:

var UserSchema = new Schema({
    interactions: [{
        interactor: {
            type: Schema.Types.ObjectId,
            ref: 'User'
        }
    }]
});

我現(xiàn)在想根據(jù)userId匹配所有interactor的值為userId的interaction,用mongoose如何能做到呢?

巴扎黑
巴扎黑

reply all(1)
伊謝爾倫

I found a solution to the matching problem, which is very intuitive:

User.find({
    'interactions.interactor': mongoose.Types.ObjectId(user._id)
}, function (err, users) {
}

But in the callback function, I will update multiple matching users. How should I save it after the update? If there is no users.save() method, do I have to write loop save myself?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template