Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 填充个人收藏';文章';使用GridFS-fs.files_Node.js_Mongodb_Gridfs_Mongoose Populate_Gridfs Stream - Fatal编程技术网

Node.js 填充个人收藏';文章';使用GridFS-fs.files

Node.js 填充个人收藏';文章';使用GridFS-fs.files,node.js,mongodb,gridfs,mongoose-populate,gridfs-stream,Node.js,Mongodb,Gridfs,Mongoose Populate,Gridfs Stream,我想在MongoDB中使用GridFS存储文件,用于不同的目的,如流式视频和保存图像。这是猫鼬文件“文章”的一部分 我在考虑对每种文件类型“视频”和“缩略图”使用不同的GridFS存储桶,但我不确定如何创建模式和模型来填充整个集合 我有这个模式,我想在每个视频和缩略图中填充fs.files var mongoose = require('mongoose'), Schema = mongoose.Schema; var ArticleSchema = new Sch

我想在MongoDB中使用GridFS存储文件,用于不同的目的,如流式视频和保存图像。这是猫鼬文件“文章”的一部分

我在考虑对每种文件类型“视频”和“缩略图”使用不同的GridFS存储桶,但我不确定如何创建模式和模型来填充整个集合

我有这个模式,我想在每个视频和缩略图中填充fs.files

var mongoose    = require('mongoose'),
    Schema      = mongoose.Schema;

var ArticleSchema   = new Schema({
    title       : { type : String, required : true },
    description : { type : String, required : true },
    votes       : { type : Number, default : 0 },
    createdAt   : { type : Date, default : Date.now },
    // ObjectID of the fs.file video
    // ObjectID of the fs.file thumbnail
});

ArticleSchema.pre('save', function(next) {
    store this files using here the createWriteStream
});

module.exports = mongoose.model('Article', ArticleSchema);
问题:

使用“pre”方法存储此集合的逻辑必须在模型中

我在这里看到了大量的示例和相关问题,但都将文件存储在控制器中的逻辑放在了模型中