【发布时间】:2019-10-13 23:29:56
【问题描述】:
所以我试图将 GridFS 集合与包含其中一些数据的架构相关联,然后用另一个模型填充它。
GridFS 架构:
const gfsSchema = mongoose.Schema({
filename: String
}, {strict: false});
const GridFs = conn.model('GridFs', gfsSchema, 'posters.files');
使用的代码:
GridFs.find({}, (err, files) => {
console.log(files);
console.log(files.filename);
});
第一个console.log 返回我所期望的:
[ { _id: 5da3a37a6587f015783637d0,
length: 3917314,
chunkSize: 261120,
uploadDate: 2019-10-13T22:21:54.389Z,
filename: 'ed49b55f58b1d5ea06ba95f18852e2a3.png',
md5: '9b52103d5c6f671023290d87b106c9cf',
contentType: 'image/png' } ]
但第二个返回undefined,尽管上面的示例显示filename 字段中有现有数据。
我需要filename 字段以便在填充时可视化图像。
【问题讨论】:
-
files是一个数组,所以它应该是files[0].filename。
标签: node.js mongoose gridfs gridfs-stream