我在 nodejs 中使用 gridfs-stream 模块来存储图像。
var db = require('config/db');
var Schema = require('mongoose').Schema;
var schema = new Schema({
name: String,
photo: Schema.Types.ObjectId // store file ObjectId
});
var model = db.model('User', schema);
model.findById('123...', function(err, user) {
console.log(user.photo) // only returning file ObjectId
console.log(user.photo.filename) // error
});
如何填充用户照片以便访问文件信息?
我知道我的数据库中有 fs.files 和 fs.chunks。但是我应该为他们创建架构以便我可以引用我的模型吗?