以下是我的代码:文件夹和文件名为:gridFs/storeAudio.js
。代码位于storeAudio.js
var mongoose = require('mongoose');
var fs = require('fs');
var Grid = require('gridfs-stream');
Grid.mongo=mongoose.mongo;
//establish mongoDB connection
var conn = mongoose.createConnection('mongodb://localhost:27017/aHolyBoly');
conn.once('open',function(){
// var gfs = Grid(conn.db);
// var db = new mongo.Db('aHolyBoly', new mongo.Server("127.0.0.1", 27017));
//var gfs = Grid(db, mongo);
var writeStream = gfs.createWriteStream({
filename:'song1.mp3'
});
fs.createReadStream('../list/hero.mp3').pipe(writeStream);
writeStream.on('close',function(file){
console.log(file.filename +'Written to db');
});
});
现在在gridFs
文件中的cmd中我正在运行命令node storeAudio.js
来创建带有集合的数据库。但是,附带的屏幕截图中显示以下错误:
注意:我之前运行了以下命令:npm install gridfs-stream
,npm install mongoose
。
如果需要更多输入,请告诉我。