这是我创建ZIP文件的示例代码。
exampleFunction: function(req, res, next){
Test.create({....
}).exec(function (error, HObj){
if(error) {console.log('error'+ error); return next(error)};
if(!HObj) {console.log('error'); return res.send({error : "error"});}
var generatedUUID=uuid.v4().replace(/[^a-zA-Z0-9]/g,'_');
var output = fs.createWriteStream(path.join(__dirname,'../../assets/images/'+generatedUUID+'.zip'));
zipArchive.pipe(output);
zipArchive.bulk([{ expand: true, cwd: path.join(__dirname,'../../assets/images/'), src: ['abc.mp3','xyz.mp3'], dest: 'newdir'}]);
zipArchive.finalize();
return res.send({zipName : generatedUUID+'.zip'});
});
}
在sailsjs控制器中连续调用此方法,导致mongo错误[error[Error (E_UNKNOWN) Encountered an unexpected error] Details: MongoError: topology was destroyed
]。
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
MongoError: topology was destroyed
at Server.insert (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:920:49)
at Server.insert (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/node_modules/mongodb/lib/server.js:324:17)
at executeCommands (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/node_modules/mongodb/lib/bulk/ordered.js:450:23)
at OrderedBulkOperation.execute (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/node_modules/mongodb/lib/bulk/ordered.js:503:10)
at bulkWrite (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/node_modules/mongodb/lib/collection.js:569:8)
at Collection.insertMany (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/node_modules/mongodb/lib/collection.js:471:44)
at Collection.insert (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/node_modules/mongodb/lib/collection.js:722:15)
at Collection.insert (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/lib/collection.js:177:48)
at Object.module.exports.adapter.create (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails-mongo/lib/adapter.js:282:18)
at module.exports.create (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails/node_modules/waterline/lib/waterline/adapter/dql.js:84:13)
at bound.createValues (/var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails/node_modules/waterline/lib/waterline/query/dql/create.js:214:16)
at /var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails/node_modules/waterline/lib/waterline/query/dql/create.js:74:20
at /var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:708:13
at /var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:49:16
at /var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:263:32
at /var/www/html/projects/RISHI/final/rishi-music_server/node_modules/sails/node_modules/waterline/node_modules/async/lib/async.js:40:16
Details: MongoError: topology was destroyed
问题是什么。帮助我。