I try to create a prototype for a mongoose schema. The database contains a row with a list of pictures.
Example :
{
"_id": ObjectId("55814a9799677ba44e7826d1"),
"album": "album1",
"pictures": [
"1434536659272.jpg",
"1434536656464.jpg",
"1434535467767.jpg"
],
"__v": 0
}
It will be awesome to know how i can inject an URL for each pictures with for example a prototype and how after i can get all the datas from the collection (with pictures and url) in JSOn format (for an API).
I tested many different approach but it doesn't work.
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var PicturesSchema = new Schema({
album: { type: String, required: true, trim: true },
pictures: { type: Array, required: false, trim: true }
});
var Pictures = mongoose.model('Pictures', PicturesSchema);
// Not working
Pictures.prototype.getPics = function(){
return 'https://s3.amazonaws.com/xxxxx/'+ this.pictures;
}
module.exports = Pictures;
How I can inject "virtually" the URL for each pictures (I don't want to store the url in the DB) ?