我正在寻找一个示例示例,用于在MongoDB
using中存储视频/图像GridFS
。我遇到了这个官方网站并按照下面的代码片段
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
请分享有关如何使用 Nodejs 中的 GridFS 在 MongoDB 中存储文件的任何链接。
编辑 1
我尝试了很多让它工作,最后我知道接口Grid
已被删除,Mongodb 2.1
所以它不起作用,但没有关于替换 Grid 的文档。现在我不清楚要使用哪一个,即GridStore
,GridFSBucket
等
该文档是否具有误导性?