我正在学习使用mongdb gridfs和nodejs驱动程序。我第一步陷入困境。
var MongoClient = require('mongodb').MongoClient;
var Grid = require("mongodb").Grid;
MongoClient.connect("mongodb://localhost:27017/kkdb", function(err, db) {
if(err) return console.log("error in connection:>>>>>>>>>>>>>>> ", 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");
}
});
});
当我运行此代码时,它会显示错误:TypeError: Grid is not a constructor