2016-04-11 13 views
0

にビデオ/画像を保存するサンプルの例を探しています。GridFSを使用しています。私は怒鳴るエラーにGridSを使用してNodeJSサーバのMongoDBにビデオ/画像を保存する

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の中のファイルを格納する方法のための任意のリンクを共有してください午前のコードを実行すると、私は

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"); 
    } 
    }); 
}); 

this official site渡って来て、以下のコードを追いました。

EDIT 1

私はそれが仕事を得るために多くのことをしようと、最終的に私はそれが動作しませんので、インターフェースGridMongodb 2.1から削除されて知るようになったが、グリッドの交換のためのドキュメントはありません。現在、どちらを使用するかについては明確ではありません。GridStore,GridFSBucketなど

このドキュメントは誤解を招くことはありますか?

+0

「mongo」は​​明白ですか?私はそうではないと思う。 – BanksySan

+0

@BanksySanどのような参照があるのか​​わかりません、私はサイトからそれを取った、あなたはそれを知っている場合は答えを投稿してください。 –

+0

3行目の変数mongoは未定義です。それ以上は明白ではありません。 – BanksySan

答えて

1

私が何をしたいことはあると信じて:

​​

require('mongodb'}オフの事:

var Db = require('mongodb').Db, 
    MongoClient = require('mongodb').MongoClient, 
    Server = require('mongodb').Server, 
    ReplSetServers = require('mongodb').ReplSetServers, 
    ObjectID = require('mongodb').ObjectID, 
    Binary = require('mongodb').Binary, 
    GridStore = require('mongodb').GridStore, 
    Grid = require('mongodb').Grid, 
    Code = require('mongodb').Code, 
    BSON = require('mongodb').pure().BSON, 
    assert = require('assert'); 

ドキュメントhereから。

+0

答えをありがとう私はこれを試して、グリッドは関数ではありません –

+0

編集を確認してください –

関連する問題