我正在尋找一個使用GridFS
在MongoDB
中存儲視頻/圖像的示例示例。我碰到this official site並遵循下面的代碼片斷使用GridFS在NodeJS服務器中將視頻/圖像保存到MongoDB中
var MongoClient = require('mongodb').MongoClient,
Grid = mongo.Grid;
// Connect to the db
MongoClient.connect("mongodb://localhost:27017/exampleDb", function(err, db) {
if(err) return console.dir(err);
var grid = new Grid(db, 'fs');
var buffer = new Buffer("Hello world");
grid.put(buffer, {metadata:{category:'text'}, content_type: 'text'}, function(err, fileInfo) {
if(!err) {
console.log("Finished writing file to Mongo");
}
});
});
當我運行的代碼我得到波紋錯誤
Grid = mongo.Grid;
^
ReferenceError: mongo is not defined
at Object.<anonymous> (D:\Rahul\Nodejs\Fileupload\fileupload\Samples\grid-fs
\mongo.js:3:8)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Function.Module.runMain (module.js:475:10)
at startup (node.js:117:18)
at node.js:951:3
請分享任何鏈接,如何將文件存儲在使用GridFS的中的NodeJS MongoDB中。
編輯1
我嘗試了很多得到它的工作,最後我才知道接口Grid
從Mongodb 2.1
刪除,這樣就不會工作,但沒有用於替換電網的文檔。現在我不清楚要使用哪一個,即GridStore
,GridFSBucket
等
本文檔是否有誤導性?
討厭陳述明顯,是'mongo'定義的?我敢打賭,事實並非如此。 – BanksySan
@BanksySan我沒有任何想法是什麼樣的參考是,我把它從網站,因爲它是從網站,你可以請張貼的答案,如果你知道 –
它告訴你,變量'mongo',第3行是undefined 。不能比這更明確。 – BanksySan