Mongo Atlas + Mongo: openUploadStream не работает - PullRequest
0 голосов
/ 25 мая 2019

Я использую это учебное пособие по gridfs , чтобы попытаться отправить мое mp4-видео на облачный атлас mongodb.Тем не менее я получаю сообщение об ошибке, что пул экземпляра сервера был уничтожен, как показано ниже.Это какая-то асинхронная вещь.Я напрямую скопировал код из api docs, но он не работает.Кажется, ошибка начинается после вызова метода openUploadStream, как это прокомментировано соответствующим образом.

client.connect(err => {
    if(err) {
        console.log('Error occurred while connecting to MongoDB Atlas...\n',err);
    }
    const db= client.db("Cluster0");
    var bucket = new mongodb.GridFSBucket(db);
    // console.log(bucket);
    // console.log(fs);

    fs.createReadStream('./somevideo.mp4')
    .pipe(
         bucket.openUploadStream('video.mp4')
     )
    // .pipe(
    //     bucket.openUploadStream('somevideo.mp4')
    // ).on('finish', function(){
    //         console.log('done!');
    //         process.exit(0);
    //     }
    // )

    

    
    client.close();
});
MongoError: server instance pool was destroyed
at basicWriteValidations (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb-core/lib/topologies/server.js:570:41)
at Server.insert (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb-core/lib/topologies/server.js:649:16)
at executeWriteOperation (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb-core/lib/topologies/replset.js:1183:37)
at ReplSet.insert (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb-core/lib/topologies/replset.js:1201:3)
at ReplSet.insert (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb/lib/topologies/topology_base.js:321:25)
at insertDocuments (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb/lib/operations/collection_ops.js:853:19)
at insertOne (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb/lib/operations/collection_ops.js:883:3)
at executeOperation (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb/lib/utils.js:416:24)
at Collection.insertOne (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb/lib/collection.js:463:10)
at doWrite (/Users/justinthong/Documents/GitHub/express-mongodb/node_modules/mongodb/lib/gridfs-stream/upload.js:433:20)
...