在mongo / mongoose中一次连接多个数据库

我们试图用mongoose连接到1500个数据库,但是使用这个命令创build1500个1500B的连接太慢了

mongoose.createConnection(url); 

1500 DB在同一个数据库服务器上。 花了超过50分钟build立这些连接。

有没有办法减less时间,或者有办法一次连接到1500 DB,因为它们在同一台服务器上?

你可以尝试asynchronous :

 'use strict'; const mongoose = require('mongoose'), async = require('async'), dbsUrl = [ 'mongodb://url1', //... 'mongodb://url15000', ]; async.map(dbsUrl, (url, callback) => { let conn = mongoose.createConnection(); conn.once('error', (err) => { callback(err); }); conn.once('connected', () => { callback(null, conn); }); }, (err, dbs) => { //If a error happenned, it will callback immediately //Else, dbs will now be a array of connections }); 

虽然我不知道这种连接数的性能。