Below is my code:The folder and filename is : gridFs/storeAudio.js
.And the code is in 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');
});
});
now in the cmd inside the gridFs
file I am running the command node storeAudio.js
to create the database with the collection.But the following error is displayed below in the screenshot attached:
Note:I ran the following commands before:npm install gridfs-stream
,npm install mongoose
.
Please let me know if any more inputs are needed.
via Aditya Jain
No comments:
Post a Comment