0
我需要保存我的次要細節。這是我的nodejs模型。更新子文件mongoose和nodejs
var mongoose = require('mongoose');
module.exports = mongoose.model('Todo', { title : String,
image:String,
bgimage:String,
secondary:[Secondary]
});
var Secondary = new mongoose.Schema({
title : String,
image:String,
bgimage:String,
tertiary :[Tertiary]
});
我在控制器的NodeJS代碼保存
Todo.findById(fields.primaryid, function (err, secondary) {
if (!err) {
Todo.secondary.push({ title : fields.title,
image : fields.file,
bgimage : fields.bgfile,
});
Todo.save();
}
});
但在我的控制檯下面的錯誤發生:
TypeError: Cannot call method 'push' of undefined
如何解決這個問題。我已經看到了很多有關這個疑問。但是沒有幫我
感謝考希克。它工作,但新保存的沒有自動生成objectid。爲此我需要做的。 – venkat
我一直在使用類似的功能,並且能夠獲得ObjectID,儘管我沒有使用自動生成的對象,而是將其自定義爲從'1'開始。 –
沒有其實我最初添加objectid _id:mongoose.Types.ObjectId();在我的中學。 – venkat