Mongo Atlas + Mongo:openUploadStream无法正常工作

时间:2019-05-25 05:06:20

标签: javascript mongodb mongodb-atlas

我正在使用此gridfs api tutorial尝试将mp4视频发送到cloud atlas mongodb。但是,我收到服务器实例池被破坏的错误,如下所示。这是一些异步的事情。我直接从api文档中复制了代码,但无法正常工作。该错误似乎始于对方法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)

0 个答案:

没有答案