File tree Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Expand file tree Collapse file tree 3 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 77const ChangeStream = require ( './cursor/ChangeStream' ) ;
88const EventEmitter = require ( 'events' ) . EventEmitter ;
99const Schema = require ( './schema' ) ;
10- const Collection = require ( './driver' ) . get ( ) . Collection ;
1110const STATES = require ( './connectionstate' ) ;
1211const MongooseError = require ( './error/index' ) ;
1312const SyncIndexesError = require ( './error/syncIndexes' ) ;
1413const PromiseProvider = require ( './promise_provider' ) ;
1514const ServerSelectionError = require ( './error/serverSelection' ) ;
1615const applyPlugins = require ( './helpers/schema/applyPlugins' ) ;
16+ const driver = require ( './driver' ) ;
1717const promiseOrCallback = require ( './helpers/promiseOrCallback' ) ;
1818const get = require ( './helpers/get' ) ;
1919const immediate = require ( './helpers/immediate' ) ;
@@ -1026,6 +1026,7 @@ Connection.prototype.collection = function(name, options) {
10261026 } ;
10271027 options = Object . assign ( { } , defaultOptions , options ? utils . clone ( options ) : { } ) ;
10281028 options . $wasForceClosed = this . $wasForceClosed ;
1029+ const Collection = driver . get ( ) . Collection ;
10291030 if ( ! ( name in this . collections ) ) {
10301031 this . collections [ name ] = new Collection ( name , this , options ) ;
10311032 }
Original file line number Diff line number Diff line change 66
77let driver = null ;
88
9+ const _mongooseInstances = [ ] ;
10+ module . exports . _mongooseInstances = _mongooseInstances ;
11+
912module . exports . get = function ( ) {
1013 return driver ;
1114} ;
1215
1316module . exports . set = function ( v ) {
1417 driver = v ;
18+
19+ for ( const mongoose of _mongooseInstances ) {
20+ const Connection = driver . getConnection ( ) ;
21+ mongoose . Connection = Connection ;
22+ mongoose . connections = [ new Connection ( mongoose ) ] ;
23+ mongoose . Collection = driver . Collection ;
24+ }
1525} ;
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ function Mongoose(options) {
7070 } , options ) ;
7171 const conn = this . createConnection ( ) ; // default connection
7272 conn . models = this . models ;
73+ driver . _mongooseInstances . push ( this ) ;
7374
7475 if ( this . options . pluralization ) {
7576 this . _pluralize = legacyPluralize ;
@@ -275,6 +276,7 @@ Mongoose.prototype.get = Mongoose.prototype.set;
275276Mongoose . prototype . createConnection = function ( uri , options , callback ) {
276277 const _mongoose = this instanceof Mongoose ? this : mongoose ;
277278
279+ const Connection = driver . get ( ) . getConnection ( ) ;
278280 const conn = new Connection ( _mongoose ) ;
279281 if ( typeof options === 'function' ) {
280282 callback = options ;
You can’t perform that action at this time.
0 commit comments