1
我想在pro_picture中插入cont和cont_type。但這不是一個嵌入式模式。如何使用貓鼬更新節點中的內部文檔
我的架構:
var userSch = new Schema({
name: String,
email: String,
profile_picture: {
cont: String,
cont_type: String
}
});
var User = mongoose.model('user', userSch);
現在我要查找其電子郵件是「[email protected]」和更新pro_picture用戶
我嘗試下面的代碼
User.findOne({email: data.email}, function (err, user) {
var userData = new User({
profile_picture: {
cont: data.pro_cont,
cont_type: data.pro_cont_type
}
});
user.profile_picture = userData;
console.log(user.profile_picture);
console.log(user);
user.save(function (err) {
if(err) throw err;
callback(rjTypes.result.SUCCESS);
});
。
它顯示
profile_picture: null //in console
但現場沒有出現在集合
嘗試記錄用戶和數據變量 – Subham