2
我試圖在Mongoose中使用save()
,但看到空集合被插入。保存方法在Mongoose失敗
我的照片模式是這樣的:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var photosSchema = mongoose.Schema({
photos: {
type: String
},
caption: {
type: String
}
});
var Photos = module.exports = mongoose.model('photos', photosSchema);
module.exports.getAllPhotos = function(callback){
Photos.findAll(callback);
}
,並在我的路線,我用我錯save
這裏做
var Photo = require('../models/photos');
router.post('/upload_photo', upload.any(), function(req, res, next) {
var photo = new Photo();
var data = {
photos:'abc.jpg',
caption:'something..'
}
photo.save(data);
res.end();
});
?我知道我可以定義像savePhoto並導出它的方法,但是如何直接使用save()
?