0
我想知道我怎麼可以更新喜歡與貓鼬數組:如何更新此模型包含對象的貓鼬陣列
var postSchema = new mongoose.Schema({
author: String,
content: String,
date: String,
likes: [{theID: String}],
numDate: Number
});
var UserSchema = mongoose.Schema({
username: {
type: String
},
password: {
type: String
},
email: {
type: String
},
first: {
type: String
},
posts: [postSchema],
last: {
type: String
},
followers: [{theID: String}],
following: [{theID: String}],
img: { data: Buffer, contentType: String },
admin: {type: Boolean, default: false}
});
我可以把東西像新職位在某個用戶通過 數據庫這樣做:
User.update({_id: req.user.id}, {
$push: {"posts": {_id : req.body.theData}}
}, function(err, user){
res.redirect('profile');
});
有沒有類似的方法可以讓我看一個特定的用戶,然後具體職位用戶擁有和更新,以推動一個字符串數組喜歡?