I'm using gridfs-stream module in nodejs for storing images.
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
});
how can i populate the user photo so that i could access the file information?
i know there're fs.files and fs.chunks in my database. but should I create the schema for them so that i could reference my model?